Jump to content

finding duplicate. very simple


coder9

Recommended Posts

Hi

 

i have 5 random numbers

 

every time i refresh the page it generate 5 random numbers.

 

how do i check them that there are no duplicate numbers between the five numbers.

 

let say 1, 4, 3, 4, 7

 

as you can see the 2nd and 4th are the same.

 

can you show me some code that will detect them in vice versa.

 

or is there a built in function in php that will do this.

 

 

Thank you.

 

 

 

Link to comment
Share on other sites

make sure it doesn't generate duplicate numbers in the first place is easier...

 

google these things  ;)

 

<?php
$numbers = array(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);
$pkt = array();
shuffle($numbers);
for ($i=1;$i<7;$i++){
$pkt[] = $numbers[$i];
}
sort($pkt);
echo "Randomly Generated Lotto Numbers <br />";
for ($d=0;$d<6;$d++){
    echo "$pkt[$d] ";
}
?>

 

http://www.spikemeister.co.uk/?p=94

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.