Submitted by Brian Element on Tue, 08/28/2012 - 12:02
This is used to create a seed value for the Rnd() function, this helps vary the output of the random seed. You would place a number as the seed, one good option is to use the Second(Now()), this would make sure that your seed is different every time you run the script.
'Random number between 1 and 100 Sub Main Dim random_number As Double Randomize(Second(Now()) random_number = Rnd() * 99 MsgBox random_number MsgBox Int(1 + random_number ) End Sub
All material provided on the IDEAScripting website is presented as is without any warranty or guarantee. Anybody using any solution provided on this pages is encouraged to validate the effectiveness and reliability on their own.
Mon, 12/16/2019 - 16:47
Random Seed for Random Sample Extraction Task
When I try to run th above code, I get a "compile error"; "syntax error" pop up that specifies this line:
I'm trying to come up with a good random number seed for the Random Sample Extraction Task and I want to esnure the seed is different and varies with the time. But, this code (nor any like it using randomize() that I've written from the language browser) does not seem to work. Does anyone know anything about this issue? Running 10.3, just need a robust rand number seed for the random sampling task that varies between macro runs.
Tue, 12/31/2019 - 10:50
I just tried it and if you
I just tried it and if you get rid of the spaces in front of the Randomize line it seems to work. No idea why this is creating a problem but just get rid of any spaces and it seems to work now.