Page 1 of 1

And Bingo was his Name-O

Posted: Tue Sep 06, 2011 7:29 am
by theyapps
Ok I am racking my head I am creating a bingo game for fun... I have function that serves as my hopper. It works pretty good, but sometimes it doesn't have a letter. I would like the result to be something like "G54". I usually get something like that, occasionally I will just get "54".

Code: Select all

function thehopper() {
    $length = 1;
    $characters = 'BINGO';
    $letter = $characters[mt_rand(1, strlen($characters))];
	$draw = $letter . rand(1,100);
    return $draw;
}
$draw = thehopper();
echo $draw;
EDIT: SOLVED: I changed the function up and this seems to work better!

Code: Select all

function thehopper() {
$alpha = str_split('BINGO');
shuffle($alpha);
$draw = implode('', array_slice($alpha, 0, 1)); 
$draw = $draw . rand(1,100);
return $draw;
}

Re: And Bingo was his Name-O

Posted: Tue Sep 06, 2011 3:46 pm
by Dorin85
Simplified:

Code: Select all

function thehopper() {
$alpha = str_split('BINGO');
shuffle($alpha);
return $alpha[0] . rand(1,100);
}
You'll probably want to store the previously called letter/number combinations so that duplicates aren't called.

Re: And Bingo was his Name-O

Posted: Tue Sep 06, 2011 5:43 pm
by twinedev
Not sure where you are from and how bingo may be played there, but here is code specific to the US normal Bingo, where you have 15 possible numbers under each letter:

Code: Select all

function thehopper() {
	$alpha = str_split('BINGO');
	$intNumber = rand(1,75);
	$draw = $alpha[floor(($intNumber-1)/15)].'-'.$intNumber;
	return $draw;
}
This makes sure that for B you only get 1-15, I you get 16-30, etc. The letters are never randomized, just the actual number, and the appropriate letter for it's column is calculated.

-Greg

Re: And Bingo was his Name-O

Posted: Wed Sep 07, 2011 3:58 am
by theyapps
Yah i just found this out my self lol i fixed this but not as gracefully as you haha