随机数在1到4000之间? [英] Random number between 1 and 4000?

查看:99
本文介绍了随机数在1到4000之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法控制rand()函数。我只是制造了一个邪恶的

数量庞大的数字。如何让它从1生成随机数 -

4000 ??

I can''t seem to control the rand() function. I just makes an evil
humongeous number. How do I make it generate random numbers from 1 -
4000??

推荐答案

eksamor写道:
eksamor wrote:
我似乎无法控制rand()函数。我只是制造了一个邪恶的数字。如何让它从1生成随机数 -
4000 ??
I can''t seem to control the rand() function. I just makes an evil
humongeous number. How do I make it generate random numbers from 1 -
4000??




你不能。但你可以用你已经获得的巨额价值来做点什么。


-

Chris" xf = = f(x) Dollin

小心三月的想法。



You can''t. But you can do something with the gynormous value you''ve
got.

--
Chris "x.f == f(x)" Dollin
Beware the ideas of March.


我现在做了这个:


int blop;


blop = rand();

while(blop> 4000 || blop< 1)

{

blop = rand();

}

printf(" blop:%d \ n",blop);


但它总是打印blop:3722

I now made this:

int blop;

blop = rand();
while (blop > 4000 || blop < 1)
{
blop = rand();
}
printf("blop: %d\n",blop);

but it always prints "blop: 3722"


你可以这样使用:


rand()%4000 + 1

u can use like this:

rand()%4000 + 1


这篇关于随机数在1到4000之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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