How to use monte carlos method without using rand()

4 ビュー (過去 30 日間)
Kenny Gee
Kenny Gee 2022 年 5 月 11 日
コメント済み: Kenny Gee 2022 年 5 月 11 日
I am trying to find a mass between 2 surfaces using monte carlos. Is there any way to use monte carlos without using the rand() function?
N=50; % points to draw
for i=1:N
x=-2+3*rand(); % random number will be generated from -2 to 1 instead of 0 to 1
y=-4+5*rand(); % random number will be generated from -4 to 1
z=-6+7*rand(); % random number will be generated from -6 to 1
end
Vol=x*y*z
  7 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 11 日
編集済み: Walter Roberson 2022 年 5 月 11 日
Or you could time some calculation repeatedly. Execution times are effectively random. They are not uniformly distributed, but if you isolated the nanoseconds then that might be uniform, maybe.
Kenny Gee
Kenny Gee 2022 年 5 月 11 日
Thank you for the suggestion. I will try to use some of them.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 11 日
You need some source of randomness. It does not have to be truly random.
There are websites that you can connect to in order to draw random numbers.
There are hardware random number generators you can get. Famously, Silicon Graphics created a random number generator by monitoring a lava lamp.
You can do things like ask for the CPU cycle counter and put the value through a Hash function.
You can monitor keypress or mouse movement timings.

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by