1. Mark Jones
  2. PowerBuilder
  3. Monday, 18 January 2021 22:45 PM UTC

It appears that some care is needed with the Randomize(0) function when used in the application startup event.   

We have reproduced that in PB 2019 4017 that the setting of the random number sequence can end up being reset.

We have an application startup script that calls various other functions,   early on in the script we call randomize(0) (which should set the random number based on the system clock) however later on the script the random number gets reset to the same point in the pseudo-random sequence.   

If we call randomize(0) again later in the script then we end up again with a random number seeded by the system clock.  There is a specific line in the script that calls a function that does relatively little - any randomize(0) before the call is reset,  randomize(0) after the call works.  Interestingly randomize(0) on the last line of the function will also get reset.   It might be a memory or corruption issue but one to look out for!  It might be a bug but I cannot be sure about this...

Mark    

Mark Jones Accepted Answer Pending Moderation
  1. Tuesday, 19 January 2021 15:24 PM UTC
  2. PowerBuilder
  3. # 1

I am adding my own response to this so that anyone else looking up this function will gain from what I have learnt.

1) This problem goes back to at least PB 6.5.1

2) It appears that registrering an object that is inherited from the system class Timing has the affect of resetting the random number generator.

3) This is reproducible in our environment...

randomize(0)
SharedObjectRegister("n_key_pusher", "key_pusher")
SharedObjectGet("key_pusher",guo_key_pusher)

messagebox("rand",rand(100))

In this case the messagebox will always display 42!

So you should always randomize(0) after calling SharedObjectRegister for a Timing class object.

I am not sure if it is a bug or expected but it is one to look out for - especially if true random numbers are critical to you!

 

Mark

Comment
  1. Miguel Leeuwe
  2. Wednesday, 20 January 2021 06:07 AM UTC
Thanks for sharing Mark!
  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.