Page 2 of 2

Re: Function Random

PostPosted: Wed May 14, 2014 2:43 pm
by Aki88
Hello Billy,

Just trying to understand this here; say I have used: FUNCTION RANDOM (X), where X is my first seed value (it can be any valid natural number, for simplicity); and I store the result of this operation in variable Y.
Now, if I use Y as a new seed for another RANDOM function, down the line in my code, then that will give me a new result; primarily because the seed itself has changed; to summarize - till the point the seed value is changing and is not same as the one used previously, the pseudo-random number generated will not be same as the previously generated value (though there is a possiblity of same numbers being generated -- very rare scenario; yet it can happen)

Re: Function Random

PostPosted: Wed May 14, 2014 2:51 pm
by enrico-sorichetti
the main point of using a seed in the first invocation of random
is to obtain repeatable results when testing

when the code is promoted to production/stage_before_that
the seed will be usually eliminated

it' probably the ONLY case where the code promoted to the last two stages
will be different than the code used in lower stages

Re: Function Random

PostPosted: Wed May 14, 2014 3:01 pm
by BillyBoyo
If you repeatedly use different seeds you will get numbers back from FUNCTION RANDOM. I have no idea whether the possibility exists for duplicates, because I wouldn't do it that way, so I've never even thought about it.

Repeatedly giving seeds will remove the distribution factor from the sequence of pseudo-random numbers you would otherwise get.

Repeatedly giving seeds will no longer give you "random" numbers. Probably. For each seed, you will get something which "looks like" a random number, but if you arrange for tens of millions of them, I'd suspect you wouldn't get the same type of distribution as you would for tens of millions in sequence from one seed.

This one I'm not going to check. Probably.

Re: Function Random

PostPosted: Wed May 14, 2014 3:15 pm
by Aki88
Well, I did end up doing something on similar lines, with around 15k compute statements, computing a random number taking the last seed as input :lol:
Completely agree on the point Billy/Enrico, that my distribution factor does get reduced; and I do remember a senior architect telling me long back that if I stick to generating-regenerating the values over and over, then there does come a point where the number generated can be a duplicate value of an already generated number; but this was long back when I was just starting out in my career and had the liberty to experiment on the test systems; lots has changed now from those good times; thinking of 15k statements just for a test run; damn, the admin might fry me for this ;)

Re: Function Random

PostPosted: Wed May 14, 2014 8:49 pm
by Robert Sample
if I stick to generating-regenerating the values over and over, then there does come a point where the number generated can be a duplicate value of an already generated number
Yes, they are called "pseudorandom" numbers because they are not truly random. There are only so many bits available for the values, and if you generate enough values you WILL get duplicates.