問題詳情

9 若某程式語言之隨機亂數函式 rand()可回傳介於 0 至 1(包含 0 但不包含 1)的隨機實數,另函式 int(x)可回傳實數參數 x 的整數值部分,今若要產生介於 1 至 6(包含 1 與 6)的隨機整數,可用以下何者算式?
(A)int(rand())*6
(B)int(6)+ rand()
(C)rand()*6+int(rand())
(D)int(rand()*6)+1

參考答案

答案:D
難度:簡單0.761905
統計:A(6),B(11),C(8),D(80),E(0)

內容推薦

內容推薦