得到范围内的随机数[10..50] [英] get random number in range [10..50]

查看:153
本文介绍了得到范围内的随机数[10..50]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


您能否建议更好的方法来生成范围内的随机数

[10..50]:


int x;

x = rand()/(RAND_MAX / 50 + 1);

if(x< 10)x = x + 10 ;


在我看来笨拙而且效率不高。


最诚挚的问候,罗马马沙克。电子邮件: mr*@tusur.ru

Hello,

can you recommend better way to generate random number within the range
[10..50]:

int x;
x = rand() / (RAND_MAX / 50 + 1);
if (x < 10) x = x + 10;

It seems to me clumsy and not efficient.

With best regards, Roman Mashak. E-mail: mr*@tusur.ru

推荐答案

* Roman Mashak写道,2006年8月22日08:35:
* Roman Mashak wrote, On 22.08.2006 08:35:

您好,


您能否推荐更好的生成方式范围内的随机数

[10..50]:


int x;

x = rand()/(RAND_MAX / 50 + 1);

如果(x <10)x = x + 10;


我觉得笨拙且效率不高。 />
Hello,

can you recommend better way to generate random number within the range
[10..50]:

int x;
x = rand() / (RAND_MAX / 50 + 1);
if (x < 10) x = x + 10;

It seems to me clumsy and not efficient.



x =(rand()%40)+ 10;

x = (rand() % 40) + 10;


boa写道:
boa wrote:

>

* Roman Mashak写道,2006年8月22日08:35:
>
* Roman Mashak wrote, On 22.08.2006 08:35:

你好,


你能否推荐更好的方法来生成范围内的随机数

[10..50]:

int x;

x = rand()/(RAND_MAX / 50 + 1);

if(x< 10)x = x + 10;


在我看来笨拙而且效率不高。
Hello,

can you recommend better way to generate random number within the range
[10..50]:

int x;
x = rand() / (RAND_MAX / 50 + 1);
if (x < 10) x = x + 10;

It seems to me clumsy and not efficient.



x =(rand()%40)+ 10;


x = (rand() % 40) + 10;



....或


x = rand()%41 + 10;


取决于具体的在[10..50]范围内意味着。


-

pete

.... or

x = rand() % 41 + 10;

depending on just exactly what "within the range [10..50]" means.

--
pete


你好,嘘!

你写的是星期二,2006年8月22日08:55:36 +0100:


b * Roman Mashak写道,2006年8月22日08:35:

??>你好,

??>>

??>你能推荐更好的方法在
$ b内生成随机数$ b ??> range [10..50]:int x; x = rand()/(RAND_MAX / 50 + 1); if(x <10)x

??> = x + 10;在我看来笨拙而且效率不高。

bx =(rand()%40)+ 10;


FAQ声称这种方法很差。


最诚挚的问候,罗马马沙克。电子邮件: mr*@tusur.ru
Hello, boa!
You wrote on Tue, 22 Aug 2006 08:55:36 +0100:

b* Roman Mashak wrote, On 22.08.2006 08:35:
??>Hello,
??>>
??>can you recommend better way to generate random number within the
??>range [10..50]: int x; x = rand() / (RAND_MAX / 50 + 1); if (x < 10) x
??>= x + 10; It seems to me clumsy and not efficient.
bx = (rand() % 40) + 10;

FAQ claims this method as very poor.

With best regards, Roman Mashak. E-mail: mr*@tusur.ru


这篇关于得到范围内的随机数[10..50]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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