random numbers -1 +1 with 2 decimals without any distribution
1 次查看(过去 30 天)
显示 更早的评论
Dear all, How can I generate random numbers ranging between -1 to +1 with 2 decimals and without any kind of distribution? Thanks in advance, Diego
0 个评论
采纳的回答
Walter Roberson
2012-1-7
With difficulty.
The -1 to +1 with 2 decimal places is not a problem (to the extent that binary floating point allows representation of 2 decimal places).
The "without any kind of distribution" is a problem. Practically everything has some kind of distribution, even if it is only Uniform Random Distribution. You will get a (researched) distribution if you were to monitor keystroke reaction times; you would get a different distribution (which would not be Uniform Random) if you asked people to enter numbers from 1 to 200.
You can get "cryptographically secure" pseudo-random generators, but those are designed to imitate Uniform Random Distribution.
You have 201 different outcomes, which is divisible by 3 (and not a prime), which interferes with using approaches such as ring theory. Besides, those approaches are for Uniform Random distribution.
Are you sure you cannot accept Uniform Random?
(randi(201) - 101) ./ 100
7 个评论
Walter Roberson
2012-1-8
Create a routine, then when called, randomly generates a mean, and then randomly generates a row that follows a beta distribution between the bounds and which has that particular mean. Next time the routine is called, it would generate a different mean for the row it is about to generate.
In this way, the mean would be fixed for any one call, but would vary with each call.
I don't know if this would serve as a "real control" for your results, but it would at least get you out of the situation of having constant means (such as 0.)
更多回答(1 个)
Image Analyst
2012-1-8
Perhaps you're simply looking for something like this:
a = -1; % Lower (min) value.
b = +1; % Upper (max) value
numberOfSamples = 50;
% Create r. Range of r is a to b.
r = a + (b-a).*rand(numberOfSamples, 1)
% Chop off beyond 2 decimal places.
samples = floor(r * 100) / 100
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!