Maxscript: Random generation from pre-defined values?

Hey, just wondering if it is possible to create something by randomly selecting between a set of pre-defined values e.g.

Make a cube by randomly selecting between 50, 100, 150, 200 as a value.

This is rather than ending up with a completely random number say 156 or 57 by using the ‘Random 1 100’ command.

Thanks for any help, really appreciate it :slight_smile:

K

values = #(50, 100, 150, 200)
index = random 1 values.length
randomvalue = values[index]

(there is a command in the python ‘random’ module that does this, if you want to take a look at that- chooses a random value from a collection).

Dont forget the seed(timestamp()) before all that or else the random will always return the same values each time you run the script :smiley:

Artur:

Dont forget the seed(timestamp()) before all that or else the random will always return the same values each time you run the script :smiley:

Really? I made a few test cases and I always get random values without modifying the seed. Of course it’s not anything good for security or encryption, but for most generic purposes, seems to work fine for me.

Of course you get the same results if you manually set the random seed to a constant every time you call the random function, but that wouldn’t make much sense unless you are really expecting a constant outcome (like for frame rendering purposes). (Oh wait, did some hw manufacturer just do that recently?)

SamiV.

Weird, I just checked this in Max 2011 and the behaviour is as expected, but in the past when I did something like:

	for i = 1 to 10 do
	(
		print (random 1 10)
	)

I would always get this result in every run:

4
6
5
7
2
5
1
10
9
6

That’s why I always use the seed(timestamp())… just in case :smiley: Sorry to misguide you!

This is what max random function looks like

Erik, so you have access both to Autodesk and Sony source code? :slight_smile:

SamiV.

Hahahaha yeah… that is awesome! xD Go SONY!

how nice… that is really awesome… Table Pads