Answered random() seeded with a specific value on database connection

JoseKreif

Member
Progress OpenEdge 10.2B
Platform: Redhat



I'm noticing that the random() function seems to be seeded with a set value when you first connect to the database.

For example,

Code:
def var i as int no-undo.

do i = 1 to 10:
  display random(1,100) with no-box 10 down.
  down.
end.

Produces

Code:
        29
        34
        10
        35
        34
        70
         4
        70
        82
        33

If you disconnect from the database, and then reconnect and relaunch the program you get the exact same result.

I guess I'm trying to understand why and what would the solution be?
 
Last edited:

JoseKreif

Member
Feel free to correct or improve, but some ingenuity seems to do the trick

Code:
def var i as int no-undo.
def var seed as int no-undo.

do i = 1 to 10:
  seed = if time > etime then
    random(etime,time)
  else   
    random(time,etime).
 
  display random(1,seed) mod 100 with no-box 10 down.
  down.

end.
 

TomBascom

Curmudgeon
It is sometimes useful to have a repeatable pseudo random sequence.

But when you don’t want that use the “-rand 2” client parameter.
 

JoseKreif

Member
It is sometimes useful to have a repeatable pseudo random sequence.

But when you don’t want that use the “-rand 2” client parameter.

Thanks for the advice. So I don't have to change the startup script for each of our many locations, I'll just keep my in-program solution. It works for what the program needs to accomplish, and won't change the way the database currently works.
 
Top