在iPhone中生成随机值 [英] generating random values in iPhone

查看:109
本文介绍了在iPhone中生成随机值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过rand()。但是,即使我重新启动应用程序,它也会给出一个特定的值。

I have used rand(). But it gives a specific value even after I restart application.

我在我的应用程序中实现了以下内容。

I have implemented following in my application.

- (void)viewDidLoad {
[super viewDidLoad];
int x,y;

x=random() % 480; y=random() % 300;

lblT.center=CGPointMake(x,y); // my label lblT
}

尝试在您的应用程序中实施,并启动应用程序。
重新启动应用程序后,您会发现该标签将具有特定值。

Try to implement in your application, and launch application. After restarting application, you will find that label will be on specific value.

推荐答案

arc4random()是一个不需要播种的内置函数(因此不会产生可以通过种子生成的可预测序列),并且它可以方便地返回整数。我从不使用任何其他东西。

arc4random() is a built-in function that does not require seeding (and so therefore does not produce predictable sequences that can be generated by using a seed), and it conveniently returns integers. I never use anything else.

这篇关于在iPhone中生成随机值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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