试图在iphone上生成随机数,得到相同的数字 [英] Trying to generate random numbers on iphone, get same number

查看:149
本文介绍了试图在iphone上生成随机数,得到相同的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作纸牌游戏。我使用以下代码绘制随机卡

I'm trying to make a card game. I'm using the following code to draw a random card

iCard = random()%55;

iCard=random() % 55;

但是icard总是从28开始。
似乎它以相同的顺序返回数字。

but icard is always starts out with 28. Seems like it gives back the numbers in the same order.

有没有办法获得不同的随机数每次首次调用函数时????

is there a way to get a diffrent random number each time the function is first called????

推荐答案

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

random() and rand() uses a seed and it is always the same seed sequence.

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

Use arc4random() it uses no seed and is 100% random

这篇关于试图在iphone上生成随机数,得到相同的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆