mardi 5 janvier 2016

Choose random value from array count

Im trying to pick a random number of a count of an array. Is there a way to convert the .count value into a UInt32? If not, is there another way to get a random value of the count of an array?

This is what I have tried so far:

    if questionTextArray.count > 0 {

        QNumber = arc4random_uniform(UInt32(questionTextArray.count)) + 1
    }

I was considering creating a for loop that would count all the elements in the array, and then convert the return into a double and then multiplying this by drand48() and then round it back to the closest Integer, but this didnt work for me... Any help is much appreciated.




Aucun commentaire:

Enregistrer un commentaire