idlelimey Posted June 9, 2009 Share Posted June 9, 2009 Hi, not sure if this works, but I've written a very simple script to generate a pattern of random tiles using a specific quantity of each colour (it's for a patchwork quilt). It works fine, but I'd like to be able to restore a sequence with a number. So, although it's random, I could type in '123456' and that would restore it. Is there a way of using a number to control the randomisation? I really don't know what to search for to find help on this, and I appreciate that my explaination is woeful at best. Any help welcome Thank you. Link to comment https://forums.phpfreaks.com/topic/161484-solved-restore-a-random-sequence/ Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 <?php mt_srand(123456); echo mt_rand(1, 100), "\n"; echo mt_rand(1, 100), "\n"; echo mt_rand(1, 100), "\n"; Those three will output the same number To get a different number you'd need a different mt_srand for each and store them somewhere. Link to comment https://forums.phpfreaks.com/topic/161484-solved-restore-a-random-sequence/#findComment-852151 Share on other sites More sharing options...
idlelimey Posted June 9, 2009 Author Share Posted June 9, 2009 Thank you, I'll give that a go and let you know how I get on. Thanks for being so prompt too, very kind Link to comment https://forums.phpfreaks.com/topic/161484-solved-restore-a-random-sequence/#findComment-852152 Share on other sites More sharing options...
idlelimey Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks again, with your help I ended up with this: $tiles = $array; if(isset($_GET['seed'])) {$seed = $_GET['seed'];} else {rand(1,999999);} echo'<p>'.$seed.'</p>'; srand($seed); shuffle($tiles); while(list(, $tile) = each($tiles)){ ... } Seems to work fine. Link to comment https://forums.phpfreaks.com/topic/161484-solved-restore-a-random-sequence/#findComment-852230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.