Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C で rand() 関数を使用して成功または失敗の割合を生成しようとしています。どのプロットを表示するかを決定する rand() 関数。」私は (some % a number) を使用するとそれができると考えましたが、行き詰まっています。
if (rand() / (RAND_MAX + 1.) < .3) { /* good soil */ } else { /* poor soil */ }
ここで、rand() / (RAND_MAX + 1.)に一様に分布する疑似乱数を生成し[0, 1)ます。この数値を比較すると.3、30% の確率で良い土壌が得られます。
rand() / (RAND_MAX + 1.)
[0, 1)
.3