random - Does the rand function ever produce values of 0 or 1 in MATLAB/Octave? -
i'm looking function generate random values between 0
, 1
, inclusive. have generated 120,000 random values using rand()
function in octave, haven't once got values 0
or 1
output. rand()
ever produce such values? if not, there other function can use achieve desired result?
if read documentation of rand
in both octave , matlab, open interval between (0,1)
, no, shouldn't generate numbers 0 or 1.
however, can perhaps generate set of random integers, normalize values lie between [0,1]
. perhaps use randi
(matlab docs, octave docs) generates integer values 1 given maximum. this, define maximum number, subtract 1 , divide offset maximum values between [0,1]
inclusive:
max_num = 10000; %// define maximum number n = 1000; %// define size of vector out = (randi(max_num, n, 1) - 1) / (max_num - 1); %// output
if want act more rand
including 0 , 1, make max_num
variable quite large.