thefollower Posted November 13, 2007 Share Posted November 13, 2007 Hey I was wondering how to assign a number from 1 to 9 to a $variable which is used by a random feature if random is possible in PHP ? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 13, 2007 Share Posted November 13, 2007 You need the rand() function http://us3.php.net/rand Quote Link to comment Share on other sites More sharing options...
thefollower Posted November 13, 2007 Author Share Posted November 13, 2007 <?php $n = rand(1,9); ?> Like that? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 13, 2007 Share Posted November 13, 2007 Yes, now $n will hold a random number between 1 and 9 Quote Link to comment Share on other sites More sharing options...
thefollower Posted November 13, 2007 Author Share Posted November 13, 2007 when you say between ... does that mean : 2 3 4 5 6 7 and 8 ? or does it include 1 and 9 Quote Link to comment Share on other sites More sharing options...
revraz Posted November 13, 2007 Share Posted November 13, 2007 Yes, but don't be surprised when the results are not very random Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 13, 2007 Share Posted November 13, 2007 It will include 1 and 9 as well. Quote Link to comment Share on other sites More sharing options...
thefollower Posted November 13, 2007 Author Share Posted November 13, 2007 Yes, but don't be surprised when the results are not very random why? How can i make it more random then ? Cos its for casino related thing and so it needs to be random... =/ Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2007 Share Posted November 13, 2007 Did you read the entry in the manual? If you did, you would have seen that it is inclusive. Ken Quote Link to comment Share on other sites More sharing options...
thefollower Posted November 13, 2007 Author Share Posted November 13, 2007 Did you read the entry in the manual? If you did, you would have seen that it is inclusive. Ken I did but when poco said between 1 and 9 i had to make sure Plus now im told i shouldn't be surprised that it isn't random .. so how can i make it nice and random =/ Quote Link to comment Share on other sites More sharing options...
revraz Posted November 13, 2007 Share Posted November 13, 2007 Run it about 20 times and check the results, if you're happy with them then you're set. But if not, then you have to try other methods to make it more random, like generating more than 1 random number and then dividing that by the number of random numbers you generate. 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.