DSPRelated.com
Forums

Looking forward to ur suggestions 4 Matlab random generator

Started by nishubhardwaj September 7, 2005
hello frnds,
I have a doubt about selecting random no generating
capacity of matlab.

Can any one suggest me using random no generator in order to randomly
select an element from a the elements of the given array?
for eg if the array is AR=[1,2, 3, 4 , 6] then the random number
generator should be able to select any element from the AR randomly

Awaiting your reply

Thanks Nishant


Hi, when you say "randomly", I assume you mean that the distribution is
uniform.

Thus, what you need is a way to generate integers i = 1...N, where p(i) =
1/N where N are the number of elements in your array.

Once these integers are generated, you can use this as an array index to
select that element from your array. So why don't you use something like
floor(N*rand(number_of_trials,1))?

In fact, if you do something like hist(floor(20*rand(100000,1))), you will
see that the distribution of the integers is nearly uniform.

hope this helps
Nandan
On 9/6/05, nishubhardwaj <nishantbhardwaj@nish...> wrote:
>
> hello frnds,
> I have a doubt about selecting random no generating
> capacity of matlab.
>
> Can any one suggest me using random no generator in order to randomly
> select an element from a the elements of the given array?
> for eg if the array is AR=[1,2, 3, 4 , 6] then the random number
> generator should be able to select any element from the AR randomly
>
> Awaiting your reply
>
> Thanks > Nishant



Hi

You can generate a uniform random variable using rand() function in matlab.
It will generate output between [0,1]. You divide the interval of [0,1] in 6
equal parts. If your random number generated lies in [0,1/6] then select
first element from AR=[1,2, 3, 4 , 6], if its in interval [1/6,1/3] it ll
select 2nd element and so on..

hope this helps

Amit Kale
>From: "nishubhardwaj" <nishantbhardwaj@nish...>
>To: matlab@matl...
>Subject: [matlab] Looking forward to ur suggestions 4 Matlab random
>generator
>Date: Wed, 07 Sep 2005 05:09:06 -0000 >hello frnds,
>
> I have a doubt about selecting random no generating
>
>capacity of matlab. >
>Can any one suggest me using random no generator in order to randomly
>
>select an element from a the elements of the given array?
>
> for eg if the array is AR=[1,2, 3, 4 , 6] then the random number
>
>generator should be able to select any element from the AR randomly >
>Awaiting your reply >
>Thanks >Nishant

_________________________________________________________________
MSN Messenger 7.5 is now out. Download it for FREE here.
http://messenger.msn.co.uk


Hello,
Try this code, It might help u.

AR=[1,2, 3, 4 , 6];
x= randperm(length(AR));
Y_out = AR(x(1)); % Y_out is the output

instaed of x(1) u can take x(2) or x(3) ... like that.
That is when u call randperm it shuffles the indexes
randomly. Just take the first element from the
jumbling indexes, U will generate randomly from the
given array.
Hope this helps.

Best Regards,
-SaiRamesh.
--- nishubhardwaj <nishantbhardwaj@nish...> wrote:

> hello frnds,
> I have a doubt about selecting random no
> generating
> capacity of matlab.
>
> Can any one suggest me using random no generator in
> order to randomly
> select an element from a the elements of the given
> array?
> for eg if the array is AR=[1,2, 3, 4 , 6] then the
> random number
> generator should be able to select any element from
> the AR randomly
>
> Awaiting your reply
>
> Thanks > Nishant

__________________________________