Init random number generator

Hi guys, I just wrote a rename script to give files a random name. See here:

	Dim n
	Dim random_number
	OnGetNewName=""
	for n = 0 to 25
		random_number = Int(rnd * 26) + 65
		OnGetNewName = OnGetNewName + chr(random_number)
	next

	OnGetNewName=OnGetNewName+getNewNameData.item.ext

The script is working fine, but each time, I restart dopus, the random number is set back to the same inital value. So it produces the same random file names over and over, which makes it pretty useless.

How can I init the random number generator with a random seed, so that each time I start dopus different results will come out? And more important, where can I find this in the docu? I'm pretty lost here - Thanks!

That's the VBScript rnd function that you're using. You can find documentation on how to use it on sites that describe VBScript:

Those pages both say you need to call this to initialise the sequence of numbers VBScript generates:

A great opportunity for the Evaluator to show off its new skills :slight_smile:

{=n = ""; for (i = 0; i < 25; i++) {n += Chr(Rnd() * 26 + 65)}; n=}

56335.orp

6 Likes

Many thanks! Works fine now, without repeating pattern!