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... Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.