Re: [請益]

看板NCKU_CSIE93作者 (只有冰與雪)時間15年前 (2008/10/05 19:37), 編輯推噓2(206)
留言8則, 3人參與, 最新討論串5/7 (看更多)
※ 引述《chys49 (丿嘎)》之銘言: : ※ 引述《boypower (321)》之銘言: : Questions: : Step1: : Create a routine GetData() to generate a float-point number between : 0 and 1 randomly. Since rand() only generate integers from 0 to 32767(i.e. : 2^15),to improve the randomness,we use the following scheme: : a□□...□15bits and b□□...□15bits = 30bits (arrays) : The first 15 bits and the latter 15 bits are generated through different : seeds. Then,through a process called normalization,which is to divide the : resulting sequence by 2^30.( Don't use time() ) 1.這裡看來 題目的意思是產生一個30bits 二進位的數字 然後再除以2^30,結果就是一個介於0於1之間的floating 2.但是呢,題目有限定這個30bits數字產生的規則 前十五個bits與後十五個bits必須使用不同的seeds(請準備兩個seeds) A.按照1跟2,首先使用兩個seeds,造出前十五個bits跟後十五個bits。 其實很簡單,就使用兩個seeds造兩個數,其大小介於0~(2^15-1) 有了這兩個數,就代表你的30bits的數字已經出來摟。 所以就順手把這兩個數字轉成二進位吧!,此時我們已經有了30個0與1 B.解著要除以2^30,但是當然不能呆呆的就給他除下去啦! 以3個bits為例子 (111=1*2^2+1*2^1+1*2^0=4+2+1=7) normalize by 2^3 觀察normalization有甚麼特殊的意義? 1*(2^2/2^3)+1*(2^1/2^3)+1*(2^0/2^3) =(1/2^1)+(1/2^2)+(1/2^3) 也就是說呢,normalize之後每個bits的意義改變為(1/(2^(30-n))) n=0~29 這裡是這題最tricky的地方,懂了才能解這題。 明白了題目normalization的意義之後,就把之前獲得的30個0與1,換成新的意義。 以3個bits為例子: 101 mormalize by 2^3 = 1*(1/2^1)+0*(1/2^2)+1*(1/2^3) = 1/2 + 1/8 把3個bits延伸到30個bits就可以得到一個介於0~1之間的floating : Step2: : Use the routine GetData() to generate 1000 float-point number data and store : them in a 1-dimensional array named Data{} (maximum capacity 1000). 這題沒意義,呼叫第一題的function一千次,把結果存在一維陣列裡面。 : Please~~ 雖然沒給code,但是已經把關鍵的地方點出來了。 試著實作看看吧。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.166.116.56

10/05 21:14, , 1F
謝謝^^謝謝^^ 我試試看~~
10/05 21:14, 1F

10/06 00:35, , 2F
我卡在seeds,用time()不夠均勻,但又想不到其它的,自己另外
10/06 00:35, 2F

10/06 00:38, , 3F
寫一個則不太成功。
10/06 00:38, 3F

10/07 01:53, , 4F
time()當seed應該滿均勻的 要不要貼code看看
10/07 01:53, 4F

10/07 13:30, , 5F
其實rand()也只是去查亂數表 seed是告訴他從那邊開始查
10/07 13:30, 5F

10/07 13:31, , 6F
像boypower所說 time()已經滿均勻了 不然可以換clock? XD
10/07 13:31, 6F

10/08 11:43, , 7F
若用time()有時亂數會重複,而且每次執行時會有某些區間很
10/08 11:43, 7F

10/08 11:47, , 8F
集中,除非讓時間夠長,所以努力K原文書中~~不知道方向對不對
10/08 11:47, 8F
文章代碼(AID): #18wAS9P6 (NCKU_CSIE93)
討論串 (同標題文章)
本文引述了以下文章的的內容:
請益
1
4
以下文章回應了本文
請益
1
1
完整討論串 (本文為第 5 之 7 篇):
請益
1
3
18年前, 10/23
請益
5
6
請益
請益
1
4
請益
2
8
請益
1
1
請益
1
6
11年前, 04/10
文章代碼(AID): #18wAS9P6 (NCKU_CSIE93)