SWIFT - Random array range 1-4 with each number only printed twice -
i'm pupil in mobile app development trying larn how assign range of numbers 1 4 array each number printed twice. can't figure out how utilize random range print numbers specific amounts of times. need response project may due in while, not now, time later.
not sure if right. i've haven't working loops, did larn them. not finish because of roadblock of how this.
by way, might help card matching game i'm making, thats why need print twice. deadline may next week.
/*for index in imagearray { imagearray[index] = }*/
to assign numbers 1 through 4 array:
var numbers = array(1 ... 4)
to assign numbers 1 through 4 twice array:
var numbers = array(1 ... 4) + array(1 ... 4)
to shuffle numbers:
var shufflednumbers = shuffle(numbers)
where shuffle
shuffle array via fisher-yates algorithm.
// see http://stackoverflow.com/a/24029847/1271826 func shuffle<t>(var list: array<t>) -> array<t> { in 0..<(list.count - 1) { allow j = int(arc4random_uniform(uint32(list.count - i))) + swap(&list[i], &list[j]) } homecoming list }
arrays random swift
No comments:
Post a Comment