1. Glenn Barber
  2. PowerBuilder
  3. Wednesday, 12 September 2018 23:42 PM UTC

We have an application which needs to select a random row from about 15000 rows.  

we are getting the value from

ll_row = Rand(ll_rowcount)

During repeated testing Ive noticed a unexpected high frequency of specific numbers (like 993) which defy the usual odds.

I am curious if anyone else has worked extensively with Rand in PB2017R3 and had similar experiences(or the contrary)

Best

Glenn Barber

Glenn Barber Accepted Answer Pending Moderation
  1. Saturday, 15 September 2018 22:50 PM UTC
  2. PowerBuilder
  3. # 1

We are using the Randomize (0) methods before calling Rand(n).  However we notice that the routine seems to be unreliable when n is larger than 14K.  I am researching what value of n causes it not to provide sufficiently random values.

Comment
There are no comments made yet.
Glenn Barber Accepted Answer Pending Moderation
  1. Saturday, 15 September 2018 22:38 PM UTC
  2. PowerBuilder
  3. # 2

We are running the windows version - java is not a workable solution for us.

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Friday, 14 September 2018 14:47 PM UTC
  2. PowerBuilder
  3. # 3

One alternative is to run a Java program to get your random number. Since PB does not support callbacks, your Java code will need to set the result in a manner that your PB code can find; i.e. a text file.
https://dzone.com/articles/random-number-generation-in-java

You can also create a function in C that does this:
https://www.geeksforgeeks.org/generating-random-number-range-c

 

Olan

 

 

Comment
  1. Glenn Barber
  2. Saturday, 15 September 2018 22:47 PM UTC
Give the similarity of the methods - I would bet that the powerbuilder version is using the C++ method described.



That said, It appears that the PowerBuilder Rand(n) method misbehaves for long's around 14K or higher.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 13 September 2018 13:55 PM UTC
  2. PowerBuilder
  3. # 4

Hi Glenn;

   Have you tried the Randomize ( ) command before using the Rand ( ) method to reset the "seed" number generator?

For example:

Randomize (ll_rowcount)

ll_row = Rand(ll_rowcount)

 

HTH

Regards ... Chris

Comment
  1. Markus Eckert
  2. Thursday, 13 September 2018 14:02 PM UTC
Or just Randomize(0)

If ll_rowcount is the same between two runs, the Random number sequence will be the same.
  1. Helpful
  1. Glenn Barber
  2. Saturday, 15 September 2018 22:43 PM UTC
I dont understand this response - are you telling me that if I Set Randomize(0) and then run

ll_row = Rand(ll_rowcount) successively that I will get the name number?? Or are you saying that if I run Rand(ll_rowcount) repeatedly in two different programs that the sequence each program returns on successive calls will be the same if ll_rowcunt is the same?



  1. Helpful
  1. Chris Pollach @Appeon
  2. Saturday, 15 September 2018 23:37 PM UTC
Hi Glenn;

The Radomize command resets the internal counters. You could use this command instead of Rand() or execute it every once in a while to reset the internal mechanisms before using Rand().

Regards ... Chris
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.