Notifications
Clear all

[Closed] random

Hello all

I have a problem… I am new to max script but not new to programming, however i cant seem to get the random to give me random numbers. I read in the help files that once the random generates a number it will always generate that number. Is there anyway to get the random to generate new random numbers over and over… I am using it in a loop and want to draw 20 boxes with random heights , widths and lengths…

please can some one help me on this small journey

here is what i have at present

numberofboxes=0

randommate = random 1 100

for i = 1 to 50 do

(

box length:randommate width:randommate height:randommate

numberofboxes=numberofboxes+1

if numberofboxes >=6 thenexit

)

regards

nebille

2 Replies

Hi, I’ve been chopping away at your script:

The following code (improved)…

numberofboxes = 0
  for i = 1 to 50 do
  (
  	box length:(random 1 100) width:(random 1 100) \
  	height:(random 1 100)
  	numberofboxes += 1
  	if numberofboxes >= 6 do exit
  )

…is the same as:

for i = 1 to 6 do
  (
  	box length:(random 1 100) width:(random 1 100) \
  	height:(random 1 100)
  )
random works fine. The problem is that you defined randommate as one random number which was used every time.

Say random gave you 87: what you defined was randommate = 87. So all through the for loop the number 87 was used instead of a random number between 1 and 100. Defining randommate and then calling it won’t result in another execution in the script after the “=”, what comes after the “=” is executed only once and the result is stored as randommate. You see?

Hope this helps,

  • R

thanks i will try that now … when i used the random before i made the variable randommate i wrote

mybox=box width: random 1 100 height:random 1 100 length:random 1 100

all without brackets…

silly me…

thanks for the correct version

regards

nebille