Random

if i wanted to have a function that returned a random number in flash mx, would it generate a new random number each time its called, each time the frame is entered or only once ever?

in php in generates a new random number each time the function is called but that doesnt seem to be happening here.

thanks for any input

Well, it all depends on how you’ve set it up exactly.

But if the random number is generated within a function, it will only be generated when the function is called.

function headshake() {
A = math.floor(math.random() * 1000)
return A
}

is approximately what i had. is there something wrong with that? it should generate a number everytime it gets that frame (because each time it calls the function again.)

a) is the function defined on the main timeline
and
b) when you call it do you call “_root.headShake();”

the function is defined in a movie clip in a movie clip, and i call it in the same frame that its defined in (more than once). should i just define it in teh main timeline and see what happens?

To make sure you get different number everytime, use time object to generate random number. I used to use it all the time when I code in java. time is good because it’s always changing.

Karzchix is 100% right on that. The time object is nice for that.

I would define the function in the _root timeline and then call out to it by a call to _root.headShake();, yes. I’m not sure if that is causing your problem or not… but it’s easier to figure out what’s going wrong if you don’t have a lot of path issues to deal with.

how would i use time to do that?

I think it goes like this

vA=Math.random()*getTimer()

though I’ve never used it myself. Looks right though.