How to use monte carlos method without using rand()

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 Comments

Well, since the method relies on repeating the calculation with a series of values representing some input distribution of the model parameters, you've got to have some way of producing those inputs.
There are libraries of sequences of random numbers that can be read or you could "roll your own" replacement, but what's the point of the Q?
Your question is confusing to me.
The Monte Carlo method, by definition, must use randomness.
There are other functions in MATLAB that could be used to generate random values, but I'm guessing that's not what you mean. Also, you could pull random values from a web site such as random.org, but again I feel like that is also not what you mean.
Maybe you could explain a bit more about what you are trying to do, and why you don't want to use rand?
sorry, i should have clarified that this is a homework assignment for numerical method class. He said he doesn't want us to use rand() function somehow. We never really go over any actual matlab coding in class and he never really answers our questions regarding coding part to solve the numerical problems. I looked over so many youtube videos and looked through sample code for random number generations. I just can't figure out how to do it without that function. We have 2 equations which creates parabola and another parabola and we are supposed to find the volume that is enclosed by those 2 parabolas with the boundaries created by their intersections points using monte carlos method.
randi(2^53-1)/2^53
or you could use randn() and calculate z-score.
Or you could code your own pseudo random generator.
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.
Thank you for the suggestion. I will try to use some of them.

Sign in to comment.

Answers (1)

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.

Categories

Find more on Random Number Generation in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 11 May 2022

Commented:

on 11 May 2022

Community Treasure Hunt

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

Start Hunting!