dimanche 1 juillet 2018

how to generate random numbers from 1 to 4 and 8 in swift

I'm making an iOS SpriteKit game right now for first time I'm developing any app and it's tough challenge for me because it's really a big project for first time. My game is a Dice game and I defined move as 4 number. So when ever I touch the screen Player moves 4 blocks, But now I want to add Dice to the Game and I need Numbers from 1 to 4 and 8. So it will be 1,2,3,4 and 8 Numbers in the Dice. I know in Swift we can get Random Numbers with "arc4random" but how do I get numbers 1 to 4 and also 8 can I do it with arc4random and if possible I need 4 and 8 numbers to come 20% more often. Any Help will be really Helpful. Thanks.




Aucun commentaire:

Enregistrer un commentaire