Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave - random generate number

I have a simple question about randomly generating numbers in Octave/Matlab.

How do I randomly generate a (one!) number (that is either 0 or 1)?

I could really use an example.

Thanx

like image 577
user1926550 Avatar asked Dec 15 '22 11:12

user1926550


1 Answers

Use rand, which generates a uniform pseudo-random number in the range 0..1, and then test this value against a suitable threshold, e.g. 0.5 for equal probability of 1 or 0:

r = rand > 0.5
like image 54
Paul R Avatar answered Jan 20 '23 15:01

Paul R