miaou — le blogv1.0.3

py_bits.miaou

← Le code · src/outil/miaou/py_bits.miaou · 23 lignes

(node py_bits
  (params (m Mt) (k Nat))
  (returns Grm)
  (intent "getrandbits(k) de Python (k au moins 1) : un mot de MT19937 décalé pour 32 bits ou moins, sinon assez de mots, et l'état d'après")
  (origin "phase 8f6 : le hasard de Python en miaou, d'après py_bits de l'outil inter (random.Random de Python)")
  (effects)
  (uses mt_mot b_shr py_mots gr_de_nat gr_fait)
  (requires
    (ge k 1))
  (ensures
    true)
  (examples
    (ex ((record Mt (mots (list 0 0)) (i 0)) 5)
      (record Grm
        (g (record Grand (neg false) (mots (list))))
        (mt (record Mt (mots (list 0 0)) (i 1))))))
  (equivalence exact)
  (body.high
    (if (le k 32)
      (let ((x (mt_mot m)))
        (record Grm (g (gr_de_nat (b_shr (get x v) (sub 32 k)))) (mt (get x mt))))
      (let ((r (py_mots m k 100000))) (record Grm (g (gr_fait false (get r ws))) (mt (get r mt))))))
  (end node py_bits))