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

### genrate uniform random variable from a set

• Email
• 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
Reply Namo 4/15/2010 3:37:04 PM

See related articles to this posting

```"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
Reply Steven 4/15/2010 4:06:45 PM

```"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
Reply us 4/15/2010 6:02:21 PM

2 Replies
361 Views

Similar Articles

12/6/2013 8:10:42 AM
[PageSpeed]