Ben Phelps Posted July 27, 2007 Share Posted July 27, 2007 I need a good method to generate a random number based on a different number. Here is the code i have now, but it doesn't work. <?php $i = 35648; if ($i <= 100) { $s = rand(100,299); } else if ($i <= 1000 & > 100) { $s = rand(300,399); } else if ($i <= 5000 & > 1001) { $s = rand(400,499) } else if ($i <= 10000 & > 5001) { $s = rand(500,749); } else if ($i <= 15000 & > 10001) { $s = rand(750,999); } else if ($i <= 20000 & > 15001) { $s = rand(1000,1499); } else if ($i <= 50000 & > 20001) { $s = rand(1500,2499); } else if ($i <= 100000 & > 50001) { $s = rand(2500,2999); } else if ($i <= 150000 & > 100001) { $s = rand(3000,3499); } else if ($i <= 200000 & > 150001) { $s = rand(3500,3999); } else if ($i <= 300000 & > 200001) { $s = rand(4000,4499); } else if ($i <= 400000 & > 300001) { $s = rand(4500,4999); } else if ($i <= 500000 & > 400001) { $s = rand(5000,5999) } else if ($i <= 750000 & > 500001) { $s = rand(6000,7499) } else if ($i <= 1000000 & > 750001) { $s = rand(7500,9999); } else if ($i <= 2000000 & > 1000001) { $s = rand(10000,14999); } else if ($i <= 5000000 & > 2000001) { $s = rand(15000,17499); } else if ($i <= 10000000 & > 5000001) { $s = rand(17500,19999); } else if ($i <= 50000000 & > 10000001) { $s = rand(20000,19999); } else if ($i <= 100000000 & > 50000001) { $s = rand(25000,29999); } else($i >= 100000001) { $s = rand(30000,39999); } echo $s; ?> Link to comment https://forums.phpfreaks.com/topic/61986-solved-generate-from-number/ Share on other sites More sharing options...
jitesh Posted July 27, 2007 Share Posted July 27, 2007 Lots of lines } else if ($i <= 1000 & $i > 100) { Link to comment https://forums.phpfreaks.com/topic/61986-solved-generate-from-number/#findComment-308630 Share on other sites More sharing options...
Ben Phelps Posted July 27, 2007 Author Share Posted July 27, 2007 It was so simple, thank you so much. Link to comment https://forums.phpfreaks.com/topic/61986-solved-generate-from-number/#findComment-308642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.