COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

genrate uniform random variable from a set

• Follow

```Is there away to genrate random number from a set of numbers

for example
random number from the set {1,3,4,6,9}
```
 0

```"Namo " <namo1983@hotmail.com> wrote in message
news:hq7br0\$mll\$1@fred.mathworks.com...
> Is there away to genrate random number from a set of numbers
>
> for example random number from the set {1,3,4,6,9}
>

Use RANDI to generate a random integer between 1 and NUMEL of the set, then
use that random integer as an index.

myset = [1 3 4 6 9];
indices = randi([1 numel(myset)], 10, 10);
values = myset(indices)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

```
 0

```"Namo " <namo1983@hotmail.com> wrote in message <hq7br0\$mll\$1@fred.mathworks.com>...
> Is there away to genrate random number from a set of numbers
>
> for example
> random number from the set {1,3,4,6,9}

one of the many solutions

s={1,3,4,6,9};     % <- set
n=5;     % <- # of randomly chosen elements of S
ix=ceil(5*rand(1,n));
r=[s{ix}]
%     r = 9     6     3     6     6     % <- current state of RAND...

us
```
 0

2 Replies
286 Views

Similiar Articles:

7/17/2012 12:11:48 AM