View Full Version : random numbers
zen
March 20th, 2003, 04:25 AM
erm.....i was just wondering how to create random numbers without ever repeating the same number twice or more
RvGaTe
March 20th, 2003, 12:14 PM
int(Math.random()*1000000000000))
creates an random number from 0 to 1000000000000
1 on 1000000000000 change to get the same number....
:D
senocular
March 20th, 2003, 02:17 PM
its usually done using an array. How many numbers do you need to be random?
ex:
//create array 0-100
randNums = [];
for (i=0;i<=100;i++) randNums[i] = i;
// randomize at once by sort
randNums.sort(function(){return random(2)*2-1});
// then step through array for each random value
// OR
// randomize as stepping through individually
for (i=100;i>=0;i--){
var rand = random(i), lastVal = randNums[i];
randNums[i] = randNums[rand];
randNums[rand] = lastVal;
}
zen
March 20th, 2003, 08:17 PM
oh i get it...using array then sort it out....(kind of comparing it right?) if its the same...then return another value if its not go on with the array....kind of troublesome...
thanks but is there an easier way like ....canceling out the numbers when it aready has been display erm...that would be assably thanks anyway
CyanBlue
March 21st, 2003, 01:32 AM
See this thread (http://64.207.155.38/forums/showthread.php?s=&threadid=17290)... Dealing the same stuff I guess... ;)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.