Decimal random number generator

15 次查看(过去 30 天)
sita
sita 2013-1-25
编辑: Thorsten 2015-10-26
Hello,
I want to generate a random number generator 0 to 1 should include values with ten decimal points.As default i get only 4 decimals.
Thanking You,
Sita
  1 个评论
Jan
Jan 2013-1-28
Where did all the comments go? Did you delete them? If so, why? Without them our answers looks a little bit unmotivated, not to say lunatic. Therefore removing important data from a thread is not wanted.

请先登录,再进行评论。

回答(3 个)

Sachin Ganjare
Sachin Ganjare 2013-1-25
编辑:Jan 2013-1-25
out = rand(1, 1);
decimal_out = floor(out * 100000000);
decimal_out = decimal_out\100000000;
  2 个评论
Cy
Cy 2015-10-26
Don't you mean "decimal_out/100000000"?
Thorsten
Thorsten 2015-10-26
编辑:Thorsten 2015-10-26
Your're right, that's a typo, must read /. Of course you can do it more efficiently in one line (for example, to generate a row vector of four random values):
x = floor(rand(1,4)*1e10)/1e10;

请先登录,再进行评论。


Jan
Jan 2013-1-25
What about using rand() directly, because it satisfies: at least 8 decimal digits already?
  1 个评论
Jan
Jan 2013-1-25
编辑:Jan 2013-1-25
The limitation to 4 digits appears in the command line only, see: help format.
format long g
disp(rand(2,2))
Although I assume your code is just an abbreviated example, I recommend not to use "min" and "max" as names of variables, because this shadows frequently used Matlab commands.
However, I still do not understand your question. What does "fixing the number of decimal points" mean? RAND does reply values like 0.00000000001 also, so what is the problem.

请先登录,再进行评论。


Evgeny Pr
Evgeny Pr 2013-1-25
编辑:Evgeny Pr 2013-1-25
Do you have the distribution law for pseudo-random numbers for your problem? You can use RAND function for generate uniformly distributed numbers and define its non-linear (or linear) transformation function:
numbers = rand(10);
transformedNumbers = transform_function(numbers);

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by