當前位置:ag真人国际官网-ag旗舰厅官方网站 » 操作系統 » linux隨機數

linux隨機數-ag真人国际官网

發布時間: 2024-07-05 22:10:52

1. linux下的random()和srand(arg), rand()這兩個生成的隨機數有什麼區別。

首先我把這三個函數原型給你看一下
long random(void);
int rand(void);
void srand(unsigned seed);
random返回的是一個0到(2^31 - 1)的long類型整數
rand返回的是一個0到rand_max的int類型整數

而你這里產生的隨機數序列是一樣的,這個很好解釋,因為你知道srand,但是你卻不知道還有一個srandom,這個函數是為random設置種子的,參數和srand一樣。
我的幫助手冊上甚至是這么寫的:
the random() and srandom() functions have (almost) the same calling sequence
and initialization properties as the rand(3) and srand(3) functions. the
difference is that rand(3) proces a much less random sequence -- in fact,
the low dozen bits generated by rand go through a cyclic pattern. all of
the bits generated by random() are usable. for example, `random()&01' will
proce a random binary value.

=============================
希望我的回答能給你帶來幫助

2. linux中,c語言for語句中的隨機數種子。

#include
#include
#include
int main()
{
int i,j;
srand(time(0));
for( i = 0;i < 1000;i )
for(j = 0;i < 100;i ){
printf("=",rand()0 1);
printf("\n");
}
return 0;
}

3. 如何在linux中用命令產生一個范圍內的隨機數

在shell中有一個環境變數random,它的范圍是0--32767
如果我們想要產生0-25范圍內的數,如下:
$random&
用這個環境變數對26取模,就可以得到最小是0,最大是25的數了。
如果想得到1--68范圍內的數,可以這樣
$randomh 1,
前面可以得到最小為0,最大為67的隨機數,再加上1,很自然的就可以得到最大為1,最小為68的數了。
如果想得到6--87范圍內的數。可以這樣
$random� 6,
前面可以得到最小為0,最大為81的隨機數,再加上6,很自然的就可以得到最大為87,最小為6的數了。

熱點內容
resin下jsp不能正常編譯 發布:2024-07-17 16:34:44 瀏覽:229
sqlserver如何切換主備伺服器 發布:2024-07-17 16:23:02 瀏覽:299
mc18伺服器ip 發布:2024-07-17 16:23:02 瀏覽:379
仙境傳說手游腳本 發布:2024-07-17 16:09:24 瀏覽:691
matlab命令窗口和新建腳本 發布:2024-07-17 15:51:26 瀏覽:375
建ftp文件夾 發布:2024-07-17 15:51:26 瀏覽:955
魔獸撿物腳本 發布:2024-07-17 15:27:56 瀏覽:130
開發ip伺服器 發布:2024-07-17 15:24:42 瀏覽:388
安卓系統視頻製作哪個好用 發布:2024-07-17 15:10:47 瀏覽:210
androidapk結構 發布:2024-07-17 15:10:43 瀏覽:945
网站地图