小编use*_*636的帖子

在arc4random()号上使用一次

如何编写不重复数字两次的arc4random()?

例如.我正在使用开关和按钮.我不想再次生成重用相同的arc4随机数.如果我有arc4random那一代数2,4,42,32,42 ......我不想再出现42.

我该如何避免这种情况?

  switch (arc4random() % 50 )
        {
            case 1:
                text.text = @"You are silly boy";
                break;
            case 2:
                text.text = @"Well, you very very silly"];
                break;
            case 3:
                text.text = @"stop being silly"];
                break;
            case 4:
                [text.text = @"silly... silly"];
                break;
            case 5:
                text.text = @"what you silly boy"];
                break;

           ...
            case 0:
                text.text = @"you silly"];
                break;
        }
Run Code Online (Sandbox Code Playgroud)

iphone random sdk arc4random

1
推荐指数
1
解决办法
2018
查看次数

标签 统计

arc4random ×1

iphone ×1

random ×1

sdk ×1