Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

random number generation

0 views
Skip to first unread message

Burcu

unread,
Jan 2, 2010, 5:32:04 PM1/2/10
to
My question is:

Generate a total of 1024 random numbers between -1023 and 1024(integers only) with almost zero mean value and standard deviation must be kept around 100.

I could not find how to generate these numbers.. I have searched for all MATLAB functions rand(), randn().. but couldnt combine all the features.. for instance when i arrenge the range of numbers i couldnt adjust the mean and std or vice versa..:(

ImageAnalyst

unread,
Jan 2, 2010, 6:09:22 PM1/2/10
to
Did you want uniformly distributed numbers or Gaussian (normally)
distributed numbers?

If you're using uniform, if you specify the range, you get the stddev
- nothing you can do about it. You could specify a stdev but then
you'd get a range that is not [-1024 to +1024]. I suppose you could
throw out numbers outside the range. Same for Gaussian - for a stdev
of 100 you'll not likely get any numbers larger than 400 or less than
-400 or so.

Here is it for Gaussian: (I just adapted the demo straight out of the
help for randn().)
workspace; % Display workspace panel.
% Generate values from a normal distribution with
% mean 0 and standard deviation 100.
r = 100 .* randn(1024,1);
% Throw out any numbers not in the range [-1024, 1024]
% This likely will not happen.
r(r > 1024) = [];
r(r < -1024) = [];
% Display results.
r_Length = length(r)
r_mean = mean(r)
r_std = std(r)
r_max = max(r)
r_min = min(r)

John D'Errico

unread,
Jan 2, 2010, 7:07:03 PM1/2/10
to
"Burcu " <burc...@yahoo.com> wrote in message <hhohh4$i66$1...@fred.mathworks.com>...

> My question is:
>
> Generate a total of 1024 random numbers between -1023 and 1024(integers only) with almost zero mean value and standard deviation must be kept around 100.
>
> I could not find how to generate these numbers.. I have searched for all MATLAB functions rand(), randn().. but couldnt combine all the features.. for instance when i arrenge the range of numbers i couldnt adjust the mean and std or vice versa..:(

Is this a matlab question?

Why are you positive that randn will not work?
What can you do to ensure that the results are
integers? Must the integers be distinct?

John

Greg Heath

unread,
Jan 2, 2010, 11:44:29 PM1/2/10
to
On Jan 2, 6:09 pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> Did you want uniformly distributed numbers or Gaussian (normally)
> distributed numbers?
>
> If you're using uniform, if you specify the range, you get the stddev
> - nothing you can do about it.  You could specify a stdev but then
> you'd get a range that is not [-1024 to +1024].  I suppose you could
> throw out numbers outside the range.  Same for Gaussian - for a stdev
> of 100 you'll not likely get any numbers larger than 400 or less than
> -400 or so.
>
> Here is it for Gaussian:  (I just adapted the demo straight out of the
> help for randn().)
> workspace; % Display workspace panel.
> % Generate values from a normal distribution with
> % mean 0 and standard deviation 100.

% For integers:

randn('state',4151941)
r = round(100 .* randn(1024,1));

-----SNIP

Hope this helps.

Burcu

unread,
Jan 3, 2010, 3:33:03 AM1/3/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <9e01fba2-4212-42b3...@u37g2000vbc.googlegroups.com>...
thanks a lot for your help.. I tried what you suggested and got numbers that are in the range of -301 and 312. Is there any way to distribute the numbers more in the range [-1023, 1024]

ImageAnalyst

unread,
Jan 3, 2010, 9:47:33 AM1/3/10
to
On Jan 3, 3:33 am, "Burcu " <burcu...@yahoo.com> wrote:
> thanks a lot for your help.. I tried what you suggested and got numbers that are in the range of -301 and 312. Is there any way to distribute the numbers more in the range [-1023, 1024]
---------------------------------------------------------------
No there is not. Like I tried to explain to you, you can't specify
ALL of the range, the standard deviation, and the shape of the
distribution. Once you specify two of them, the third one is pretty
much determined. Think about it. Can you imagine otherwise? No -
you will not be able to. If you want a higher proportion of numbers
in the range 312 to 1024, then the std dev will no longer be 100, will
it? No of course it won't.

Burcu

unread,
Jan 3, 2010, 11:05:05 AM1/3/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <80b12354-3415-4df5...@r10g2000vbn.googlegroups.com>...

Oww thats right thanks a lot!

0 new messages