123456789101112131415161718192021222324252627282930313233343536 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
- "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
- <sect1 id="Non-Random_RANDOM">
- <title><emphasis role="bold">Non-Random RANDOM</emphasis></title>
- <para>There are occasions when you need a random number, but once
- you've gotten it, you want that value to stay the same for the duration of
- the workunit. For example, the “problem” with this code is that it will
- OUTPUT three different values (this code is in
- NonRandomRandom.ECL):</para>
- <programlisting>INTEGER1 Rand1 := (RANDOM() % 25) + 1;
- OUTPUT(Rand1);
- OUTPUT(Rand1);
- OUTPUT(Rand1);</programlisting>
- <para>To make the “random” value persistent throughout the workunit, you can
- simply add the STORED Workflow Service to the attribute definition, like
- this (this code is also in NonRandomRandom.ECL):</para>
- <programlisting>INTEGER1 Rand2 :<guimenu>=</guimenu> (RANDOM() % 25) + 1 : STORED('MyRandomValue');
- OUTPUT(Rand2);
- OUTPUT(Rand2);
- OUTPUT(Rand2);</programlisting>
- <para>This will cause the “random” value to be calculated once, then used
- throughout the rest of the workunit.</para>
- <para>The GLOBAL Workflow Service would accomplish the same thing, but using
- STORED has the added advantage that the “random” value used for the workunit
- is displayed on the ECL Watch page for that workunit, allowing you to better
- debug your code by seeing exactly what “random” value was used for the
- job.</para>
- </sect1>
|