Function Random



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Re: Function Random

Postby Aki88 » Wed May 14, 2014 2:43 pm

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)
Aki88
 
Posts: 371
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 35 times

Re: Re: Function Random

 

Re: Function Random

Postby enrico-sorichetti » Wed May 14, 2014 2:51 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Function Random

Postby BillyBoyo » Wed May 14, 2014 3:01 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Function Random

Postby Aki88 » Wed May 14, 2014 3:15 pm

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 ;)
Aki88
 
Posts: 371
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 35 times

Re: Function Random

Postby Robert Sample » Wed May 14, 2014 8:49 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Previous

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post