Random, .. not so random?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Random, .. not so random?

Post by hoangvo81 » Mon Mar 17, 2014 6:37 pm

Hi,

can someone also confirm this on their version?

I am running ver 14.0.16

codes:

Code: Select all

    let>k=0

repeat>k
    let>RND_SEED=1000
    add>k,1
    random>10000,value
    writeln>c:\temp\random.txt,wr,%value%
Until>k=100


result is 3799
every entry. - your's might be different not sure.

problem i found is that when i did the Let>RND_SEED=1000
this for some reason determine what the first number is, i thought this was a seed value starting and shouldn't matter if i increase it or decrease it.

random is fine if i take the seed statement out of the loop. But this means that my first number will always be 3799 and not a random number between 1000 and 10000.


----
edit:
i also notice that if i take the seed out of the loop,
run the script, rename the file
run the script again, and the result in the two file are exactly the same.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Mar 17, 2014 8:06 pm

Can confirm if I set rnd_seed the results are always the same. That is definitely a bug. But if I take it out the results are random.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Tue Mar 18, 2014 4:28 pm

Setting the seed WILL always give you the same number.
It is supposed to.

Typically, with seed not set, the seed is determined through some date and time stamp(?) or some other wildly variable choice.

The numbers that are generated after setting the seed should be random but those numbers will be the same for that seed every time it is used.

This makes it possible to debug problems.
"When seed = xxx, then my code fails"
The only way I have to debug this, is to be able to set the seed manually.

If you want a number between 1000 and 10000 then set try something like this...
Let>UpperLimit=10000
Let>LowerLimit=1000
Ran>{%UpperLimit%-%LowerLimit%},rr
Let>rr=rr+LowerLimit
Thanks,
Jerry

[email protected]

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Mar 20, 2014 9:48 am

Sorry, correct, I wasn't thinking. It's not a bug after all :-)

http://en.wikipedia.org/wiki/Random_seed
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Post by hoangvo81 » Fri Mar 21, 2014 2:56 pm

thanks for clearing that up.
i'll just add the min limit values to the result.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts