小编Rom*_*man的帖子

如何在Objective-C中创建随机浮点数?

我正在尝试在Objective-C中创建0.15到0.3之间的随机浮点数.以下代码始终返回1:

int randn = (random() % 15)+15;
float pscale = (float)randn / 100;
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

random floating-point objective-c

33
推荐指数
2
解决办法
4万
查看次数

标签 统计

floating-point ×1

objective-c ×1

random ×1