Skip to main content
1 of 5
ciao
  • 26k
  • 2
  • 61
  • 142

It is almost always a bad idea to generate random variates one at a time in a time-sensitive construct in MM. This is a rudimentary way of doing a sim. run, with a million variates queued up:

len = 15
box = 2^len - 1
cnt = 1
Catch[Scan[(If[(box = BitXor[box, #]) == 0, Throw[cnt], cnt++]) &, 
   2^RandomInteger[len - 1, 1000000]]] 

Folding it instead of scanning may well be faster.

ciao
  • 26k
  • 2
  • 61
  • 142