dimanche 25 juillet 2021

SwiftUI - How to get random number within a certain range

I want to bring in a random number within a certain range.

It's hard to explain, so I'll replace it with code.

func getImage(indedxLocation: Int) -> String {
    let getNumber = indexLocation % 20   // value is 0 ~ 19
    let getRandom = getNumber.random(in: 0 ..< 4)  // I want to solve this part

    return String(getRandom)
}

This code is written the way I want it and I want to know the correct logic of this code.

Thank you.




Aucun commentaire:

Enregistrer un commentaire