Page 1 of 1

Rnd() gives diff. op's in parallelly running Jobs vs Manager

Posted: Fri Dec 16, 2005 4:17 pm
by ameyvaidya
This post/doubt is a result of tests done for <A Href="viewtopic.php?p=156772#156772">this</A> Post
In order to test if the RND function returns unique values when called in Jobs executing simultaneously, I created a routine with Just the 2 lines:

Code: Select all

RANDOMIZE (@NULL)
Ans=RND(99999)
This routine was used in 5 instances of the same multi-instance Job using about 200 rows of input data to generate 200 random numbers per job.

A sequence calls all 5 invocations in parallel.

(and yes i had some time on my hands :roll: to try this out)

The results are documented in the above link.

The reason for this post is the strange thing I'd noticed when testing the routine I'd built for this test was that if I used randomize(@NULL) in the routine, it generates the same value across 5 different test rows(Dummy arguments and using "Run All"). If I rem'med the randomize() function, it would return unique random numbers. This is the exact opposite of what i noticed when using this routine in the 5 instanced Job

The question this raises is that how does the Manager do the Test for routines?

Does each routine call spawn a new process (i feel this is unlikely)
or
One sIngle process runs all the test rows one after the other? If so, after a test run, is this process killed and an new one started for each test run?


Any other details (pages in manuals, links to docs, etc) would be very very velcome :-)

Posted: Fri Dec 16, 2005 6:31 pm
by chulett
From the BASIC pdf manual:
Use the RANDOMIZE statement with an expression to make the RND function generate the same sequence of random numbers each time the program is run. If no expression is supplied, or if expression evaluates to the null value, the internal time of day is used (the null value is ignored). In these cases the sequence is different each time the program is run.
So, this function sets the 'seed' that the string of (psuedo) random numbers are generated from. Same seed = same string of 'random' numbers.

Posted: Sat Dec 17, 2005 2:42 am
by ArndW
I responded to the other post before replying here.

A random number generate is never random, it is pseudo-random. The algorithm distribute elements in the series as randomly as possible across the available range of numbers. But in order to be used for prediction purposes it needs to be repeatable and verifiable, thus the seed or RANDOMIZE() function.

Just like any series, if you start in the same place you will get the same numbers in the same order. Any seed you choose is going to be better than the constant value you chose.

Posted: Tue Dec 20, 2005 11:21 am
by ameyvaidya
Thanks, Arand and Craig.