srand有大数字 [英] srand with big numbers

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

问题描述

我已阅读并研究并查看了参考文献,但无法确定

如何做到这一点。这里有一些真正的知识现在让我们看看

clc中谁知道那些东西;)


main(void){

srand(time(NULL));

printf("%i \\ n",rand());

返回0;


现在简单而前进这里我很难过。我希望以上述方式返回的随机值

为长双倍,相当于

pow(2,128)。但是srand在我的系统上使用了无符号的32位,而且我的系统上的长两倍
是96位,或12个字节。我找不到转换函数和

我不知道我是否需要演员表。可以将srand的随机值2返回到128

的功率?我知道这可以做到。有人请告诉我。


谢谢

解决方案

Bill Cunningham写道:


我已阅读并研究并查看了参考文献,但无法确定

如何做到这一点。这里有一些真正的知识现在让我们看看

clc中谁知道那些东西;)


main(void){

srand(time(NULL));

printf("%i \\ n",rand());

返回0;


现在简单而前进这里我很难过。我希望以上述方式返回的随机值

为长双倍,相当于

pow(2,128)。但是srand在我的系统上使用了无符号的32位,而且我的系统上的长两倍
是96位,或12个字节。我找不到转换函数和

我不知道我是否需要演员表。可以将srand的随机值2返回到128

的功率?我知道这可以做到。有人请告诉我。



srand()播种伪随机数生成器,它不会返回任何内容。


rand()一个int,范围是0到RAND_MAX。 RAND_MAX仅保证

为32767.


您将不得不使用平台扩展来获得更大的随机数。


-

Ian Collins。



你将不得不使用平台扩展以获得更大的随机数。



确定您可能建议的任何内容吗?


Bill


Bill Cunningham写道:


>你将不得不使用平台扩展来获得更大的随机性数字。



确定你可以推荐什么?



如果你使用Unix / drand48系列Linux平台。


尝试一个特定于平台的编程小组。


-

Ian Collins。


I have read and studied and looked at references and can''t find out how
to do this. Here''s where some real knowledge comes in now lets see who in
clc really knows there stuff ;)

main(void) {
srand(time(NULL));
printf("%i\\n",rand());
return 0;

Simple and forward now here''s where I''m stumped. I want the random values
returned in the above way to be long doubles and the equivalent of
pow(2,128). But srand takes an unsigned 32 bit on my system and long double
is 96 bit on my system, or 12 bytes. I can find no conversion functions and
I don''t know if I need casts. Can srand return random values of 2 to the 128
power? I know this can be done. Someone please show me.

Thanks

解决方案

Bill Cunningham wrote:

I have read and studied and looked at references and can''t find out how
to do this. Here''s where some real knowledge comes in now lets see who in
clc really knows there stuff ;)

main(void) {
srand(time(NULL));
printf("%i\\n",rand());
return 0;

Simple and forward now here''s where I''m stumped. I want the random values
returned in the above way to be long doubles and the equivalent of
pow(2,128). But srand takes an unsigned 32 bit on my system and long double
is 96 bit on my system, or 12 bytes. I can find no conversion functions and
I don''t know if I need casts. Can srand return random values of 2 to the 128
power? I know this can be done. Someone please show me.

srand() seeds a pseudo-random number generator, it does not return anything.

rand() an int the range of 0 to RAND_MAX. RAND_MAX is only guaranteed
to be 32767.

You will have to use a platform extension to get bigger random numbers.

--
Ian Collins.


You will have to use a platform extension to get bigger random numbers.

OK anything you might suggest?

Bill


Bill Cunningham wrote:

>You will have to use a platform extension to get bigger random numbers.

OK anything you might suggest?

The drand48 family if you are using a Unix/Linux platform.

Try a platform specific programming group.

--
Ian Collins.


这篇关于srand有大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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