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 ? Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/ 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 Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390869 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? Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390870 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 Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390873 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 Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390876 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 Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390879 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. Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390880 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... =/ Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390881 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 Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390884 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 =/ Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390887 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. Link to comment https://forums.phpfreaks.com/topic/77202-assign-a-number-from-1-to-9/#findComment-390896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.