Using B9500092 Get Random Number

sopchek

sopchek

Member
Hi guys,

Tell me if I`m wrong but function B9500092 is meant to return random numbers. But the way C code of it looks and works is strange. jdePPSRand() (srand() in C) generates the seed or 'starting point' for generating a series of pseudorandoms and jdePPRand() (rand() in C) outputs these values. Also '1' resets srand() as it said in C Documentation.

So, I mean I get the same random number every time (i.e. '1' - > '41') because rand() is done only once in a procedure. Also I tried to did B9500092 multiple times (just pass seed first and recieve rand() after a while:
<font class="small">Code:</font><hr /><pre>00001 -GenerateRandomNumber(B9500092.GenerateRandomNumber)
FC INT1 [INT01] -> nInputNumber [INT01]
00002 -GenerateRandomNumber(B9500092.GenerateRandomNumber)
00003 -GenerateRandomNumber(B9500092.GenerateRandomNumber)
00004 -GenerateRandomNumber(B9500092.GenerateRandomNumber)
FC INT2 [INT01] <- nRandomNumber [INT01]

</pre><hr />
but it act as I input '1' all the time.

Maybe I missed something?
 
Looking at that code, I would say that is not a very well written random number generator. Maybe it was written for a very specific purpose, but it's not very generic-friendly IMO. You should still be able to use it, but you will have to provide a more random seed (nInputNumber) yourself.

I've usually seen the seeding using a time value to provide more randomness. You can't just use the same value for nInputNumber as that will always produce the same sequences of random numbers.

I suppose you could try using the E1 time of day as your input. Depending on your requirement and use of the function, it may prove suitable. Just be aware that if your process should happen to call this function more than once in the same second, you will get the same random number for each.

You could also write your own that is more flexible. I would write it in such a way as to being able to gen a random number between any two numbers.

Oh, and I notice you're calling the bsfn multiple times...if that is your plan to get each successive random number in the seeded sequence, it won't work that way. That function is designed to generate and return 1 random number.
 
Back
Top