SyntaxPro Posted November 30, 2010 Share Posted November 30, 2010 I need to generate 3 random numbers from 1-100... but Math.random() 3 times in a row seems like each number is very close to each other... Link to comment https://forums.phpfreaks.com/topic/220272-random-generator/ Share on other sites More sharing options...
requinix Posted November 30, 2010 Share Posted November 30, 2010 JavaScript I assume? Math.random() creates a random number between 0 and 1. To adjust that to between 1 and 100 use some math. Math.floor(Math.random() * 100) + 1 Link to comment https://forums.phpfreaks.com/topic/220272-random-generator/#findComment-1141478 Share on other sites More sharing options...
SyntaxPro Posted November 30, 2010 Author Share Posted November 30, 2010 Is it just me or does calling the Math.random() function fail? I was doing Math.floor(Math.random() * 100) + 1, but even still it seems like because im calling it so close to each other they're so close... Example (it seems like) a = Math.floor(Math.random() * 100) + 1; would be like 2 b = Math.floor(Math.random() * 100) + 1; would be like 45 c = Math.floor(Math.random() * 100) + 1; would be like 89 see how it gets higher as u go down the row? it seems to do that a lot... anyone know why? Link to comment https://forums.phpfreaks.com/topic/220272-random-generator/#findComment-1141512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.