what would be the advantages of using either one of these over the other? it seems to me that if I wanted values between 1 and 100 I would rather use random(100) as it could return ANY integer value from 0 to 100… if I use Math.random()100 I can only get these values:
0.0100 = 0
0.1100 = 10
0.2100 = 20
0.3100 = 30
0.4100 = 40 …etc. ie I can only get 10 different values!
Is this correct, is there a way around this??? any info would be great!! Thanks
Peace
ahhh yes, I see, I was unsure how many places back the number given went… that must be the problem I am having - that is my MCs are random, but… I guess not THAT random…hmmmm
Math.random(); produces a number between 0 and 1 but it returns that number as a three digit integer so you will get any value you like
Math.random(); could therefore come up with this ‘.234’
which would be 23.4 if you multiplied it by 100. Rounded it would be 23.
For the record, the old ‘random();’ method has been depreciated… so there is a good chance that the next version of Flash will not allow it at all as a method. So get used to using the ‘Math’ methods.
In addition… the math method is more random. I know that sounds weird. How can anything be more random than another random number… but that’s how computers work.
Why was Math.round() depreciated? I think it is a handy tool for making whole numbers instead of the standard decimal number that regular Math.random() gives you.
Is there another way to doing this without using Math.round()?
thanks for all the info guys! BTW lostinbeta: my troubles were not what I had thought… another simple number error that was excluding most of the, uh “randomness” of my MC… once again one of those darn little things. Everything is working VERY well now.
Peace
When I used Math.random()*100 I got numbers like 45.5251852050424. That is 15 digits, a very big number. I am glad to see that round() wasn’t depreciated, because I tend to use that a lot. I am not one for decimal numbers.
RYALL: Glad to see you got everything up and working:)
FYI, my friends… random and round were deprecated not depreciated.
There is also a problem with just using Math(random) because it will provide random numbers BETWEEN, but not including, the start and end numbers.
The proper format, in my opinion, should be:
min=1;
max=100;
Math.floor(Math.random()*((max-min)+1))+min;
This will cover all numbers from 1 to 100, without exclusions.
I vaguely remember one other reason why you should use Math.floor and Math.random… it had to do with certain numbers showing up more often than others. I remember it was Supra who is instructed me on this phenomenom.
Ahhhhhh - thanks Iammontoya! That helps me out, I was using quite a hack to set the range of values I needed, thanks this way is a lot cleaner - and you say it comes up different numbers more often? interesting, I wonder why. Works for me!
PS did you ever make any headway on that .fla I sent you? The one with the mouse trailer (reading: International Importers, Inc.) and the preloader conflict?
Thanks for the new info. I didn’t know Math.random() only did the numbers BETWEEN your start and end numbers. That is definitely good to know. I used regular Math.random() for a random frame effect, but It wouldn’t play the last frame, definitely explains why.
It is also good to know about the Math.floor() thing.
Oh, I always start everything with Math. I thought you meant that it was gone for good. Phew.
Hey Montoya, what is the difference between Math.floor and Math.ceil? To me that looks like floor and ceiling, and I have no clue what the difference is.
Does it have anything to do with it choosing higher or lower numbers more often?