Randomize()

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.

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

IDEAScript Language:

Comments

Hello All,
When I try to run th above code, I get a "compile error"; "syntax error" pop up that specifies this line:
Randomize(Second(Now())
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.
Thank you. 

Brian Element's picture

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.