3 Replies Latest reply on Jan 17, 2009 7:48 AM by [Jongware]

# [JS CS3] Check the pattern of a random number given a specific data ?

Hi all,
I succeed getting a random number of this look : d.dd (8.73 for ex)
I use Math.random()*(max-min)+min;
I want to check that this number respect a specific given increment.

To be clear :
If I set min to 0 and max to 10 for example.
The script returns a number like 8.56

Now, I have a increment like 0.2
I want the script to give me a number that can be d,d.2,d.4,d.6,d.8
BUT NOT d.78 or d.1

I guess I may use a while command but have no idea of the checking operation.
Any idea ?
Loic
• ###### 1. Re: [JS CS3] Check the pattern of a random number given a specific data ?
Math to the rescue. You want a random integer div 5.

Math.floor(5*(Math.random()*(max-min)+min))/5 should do it.
• ###### 2. Re: [JS CS3] Check the pattern of a random number given a specific data ?
Hi jongware,
Thanks a lot, that's really what I needed.
I hope I can master your logic one day ;-)
Loic
• ###### 3. Re: [JS CS3] Check the pattern of a random number given a specific data ?
>I hope I can master your logic one day

Ho boy. Be careful what you wish for :D