help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rand implementation question


From: mpender
Subject: Re: Rand implementation question
Date: Thu, 27 Feb 2014 19:04:51 -0800 (PST)



If I need a random bit (or sequence of say 10000) I usually do:

a=(rand(1,10000)>0.5);

Dmitri.
-- 

I realized after posting the question that I totally messed it up --- round
(0.5) would always result in 1 as the outcome anyway.  I was trying to
simplify something I extracted from a more complicated piece of code.  That
said, I like the '>' approach instead of round for binary variable
extraction.  The only downside I see to it is that the Mersenne twister must
generate a new random value for each element of 'a' in the sequence.  There
should be some efficient way to extract multiple bits from a single
double-precision floating point value returned by the Mersenne twister.

- Mike



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Re-Rand-implementation-question-tp4662472p4662474.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]