random numbers -1 +1 with 2 decimals without any distribution

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

 Accepted Answer

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 Comments

Hi Walter,
How can I use your example for 187 rows and 51 columns?
On the other hand, I'm generating those numbers to use them as a control for my xcorr coeff values, that follow a normal distribution. So my first thought was creating a random matrix of numbers that followed a normal distribution, like this:
G=random('Normal',0,1,187,51)
After that I ran xcorr coeff to the resultant matrix.
As you can see, what I got when I boxplotted both results was a box centered at point 0 following a normal distribution, that doesn't seems to serve as a "real" control for my actual results.
Uniform Random may do the job???
Thanks,
Diego
Oh well, I created the random matrix this way:
G=randi([-100 100],187,51);
G=G /100;
Now I can try...
Well, it seems the control will always be centered at point 0.
Thanks again Walter.
Regards,
Diego
There are distributions that are compatible with being finite on both ends and having an expected value that is not the average of the endpoints. Any one such distribution would have a fixed "expected value". I get the impression you would like a different expected value for every run (or for every row?) If so, that might be possible to implement provided all of the data for a single expected value was generated at the same time.
I didn't understand the last part Walter. May I ask you to explain that a little bit more?
Thanks,
Diego
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.)
Thank you Walter.
It seems that the only way I can get real controls is by randomly sampling real subjects instead of generating random numbers.
However, random numbers will help me in selecting the subjects to be sampled.
Best,
Diego

Sign in to comment.

More Answers (1)

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

1 Comment

Thank you Image Analyst,
I tried your example and is good.
However I'm still getting a mean pointed around zero.
As I reply to Walter, it seems that the only way of getting real controls is by using real subjects randomly selected.
Best,
Diego

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!