Saturday, 17 August 2013

PHP Random Number Generator Using Array and substr

PHP Random Number Generator Using Array and substr

I'm trying to build a simple lottery number generator for my own
ammusment. I have to pick six numbers between 1 & 49, obviously without
repeats.
I have tried using the mt_rand feature for six different variables then
echoing them in order but I guess there is the possibility of repeated
numbers. So I'm now trying to get the following to work.
<?php $randomString =
substr(shuffle("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49"),
0, 6); echo $randomString; ?>
I know that substr is for strings and not arrays but I can't find the
alternative.
Anyone got a solution?

No comments:

Post a Comment