fork download
  1. (defconstant +experiments-number+ 10000000)
  2.  
  3. (with-open-file (rand #P"/dev/urandom" :element-type 'unsigned-byte)
  4. (loop :repeat +experiments-number+
  5. :sum (ecase (logand #b11 (read-byte rand))
  6. ((#b10 #b01 #b11) 1) ;; Здесь уже очевидно, что вероятность составляет 3/4
  7. (#b00 0))
  8. :into number-of-wins
  9. :finally (format t "~a (~a)~%"
  10. #1=(/ number-of-wins +experiments-number+)
  11. (float #1#))))
Success #stdin #stdout 0.76s 25652KB
stdin
Standard input is empty
stdout
7501739/10000000 (0.7501739)