List of random numbers - arc4random

前端 未结 2 1047
春和景丽
春和景丽 2021-01-27 17:52

I want to create an array of numbers from 0-9 and want them to be randomized

Meaning, when a user clicks on a UIButton it creates an NSMutableArray of objects 4,5,8,3,6,

相关标签:
2条回答
  • 2021-01-27 18:20

    You might want to use Random and Linq

    Random random = new Random(0);
    var myRandom = Enumerable.Repeat(0, n).Select(i => random.Next(0, 9));
    

    where n is the amount of digits you want

    Hope that helps

    0 讨论(0)
  • 2021-01-27 18:27

    As per this SO answer whats-the-best-way-to-shuffle-an-nsmutablearray, just create your list of numbers 0..9, (or 0..1000, whatever) in a mutable array and then randomly shuffle them.

    0 讨论(0)
提交回复
热议问题