MATLAB: Generate a random decimal number between 0 and 1

random number generator

Hi guys. Do you know how can I generate a random decimal number between 0 and 1? I tried x=randi(0 1) but this doesn't work for some reason.
Thank you.

Best Answer

So why not try rand?
When you have a problem in MATLAB, use tools like help and lookfor to learn how to solve them. For example, you know how to use randi. So read the help for randi.
help randi
...
At the bottom of what you see, you will find this line:
See also rand, randn, randperm, rng, RandStream
The see also line is of huge importance here, because it gives you hints about related functions. Now, look at the help for those tools. You might find the first one suits your purpose EXACTLY.
Next, if you have no idea how to use any tool, including randi, you could also have used lookfor. I just tried
lookfor random
A few lines down there, I found this:
rand - Uniformly distributed pseudorandom numbers.
Hmm. Do you think rand might help you to do this? READ THE HELP FOR RAND. Lookfor can help you to find the tools you need to use.
Finally, if you have no idea how to do any of this, then you REALLY need to read the short courses out there, as this is a really basic question. Try the MATLAB Onramp tutorial. Or look on Youtube, where a quick search turned up at least a few user created tutorials on MATLAB.
It is ok to read the manual.
Related Question