This question already has answers here:
Why do I always get the same sequence of random numbers with rand()?
                                
                                    (11个答案)
                                
                        
                        
                            Does stdlib's rand() always give the same sequence?
                                
                                    (6个答案)
                                
                        
                                5年前关闭。
            
                    
我正在尝试制作纸牌游戏。我正在使用以下代码绘制随机卡

iCard = random()%55;

但是icard总是以28开始。
好像它以相同的顺序返回数字。

有没有办法在每次调用该函数时获得一个不同的随机数?

最佳答案

random()rand()使用种子,并且始终是相同的种子序列。

使用arc4random()它不使用种子并且是100%随机的

关于ios - 尝试在iPhone上生成随机数,获得相同的数字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24111643/

10-14 20:08
查看更多