vendredi 29 mars 2019

Generate a 9 digit number with no more than 3 duplicate numbers

I'm trying to create a scratch card like system in php that displays a winner or loser based on random generate numbers.

I know i can create a random number using mt_rand or rand ranging from 0-9 but the issue i have is making sure there is no more than one duplicate of 3

9 digit number is out put with 100% no matching digits or a 9 digit number with one number appearing a maximum of 3 times like so 2948410427

the reason i am doing it this way is i have a lot of themed cards each theme has 10 small icons these icons are numbered 0-9 web the user opens my application it will randomly select a theme and then send a request to my server with this theme

the server will then generate the numbers and then these numbers will be output in json like so

{
    "Theme": "Space",
    "one": 3,
    "two": 6,
    "three": 0,
    "four": 7,
    "five": 1,
    "six": 3,
    "seven": 2,
    "eight": 9,
    "nine": 3,
    "winner": true
}

my application will then use these numbers to link to the images

1.png
2.png
3.png

and so on filling up the scratched grid.

this is the best way i can think todo it wile also allowing for random theme selection and random winners.

if anyone else can think of a better way i would be happy to hear it.




Aucun commentaire:

Enregistrer un commentaire