iPhone: random() function gives me the same random number everytime

前端 未结 8 2123
情书的邮戳
情书的邮戳 2020-12-09 14:02

I am using function random()%x for the generation of a random number, but every time I start the application I see that it creates or generates the same number.

Lik

相关标签:
8条回答
  • 2020-12-09 14:22

    You'll likely have better luck with arc4random(), you don't need to explicitly seed it and it seems to be a "better" random.

    0 讨论(0)
  • 2020-12-09 14:30

    Call srandomdev() first.

    srandomdev();
    long my_rand = random();

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