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.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -