วันจันทร์ที่ 6 กรกฎาคม พ.ศ. 2552

[ matlab ] uniform distribution of random

The random number from

 > > round(rand(1)*1000) 


does not have uniform distribution. You should use

 > > floor(101*rand) 

or
 > > ceil(101*rand-1) 


to get a uniform distribution.

Each number would then have a probability of 1/101 of being chosen.

In general, to get uniformly distributed integers in the range [m,n] (including the endpoints) use:

 > > floor((n-m+1)*rand+m) 

or
 > > ceil((n-m+1)*rand+m-1) 


or you can use

 > > temp=randperm(n);

 > > random_integer=temp(1);


ref : derkeiler

ไม่มีความคิดเห็น:

LinkWithin

Related Posts Plugin for WordPress, Blogger...