 M: sfmt random-32* ( sfmt -- n )
     dup refill-sfmt? [ dup generate ] when next ; inline
 
+M: sfmt seed-random ( sfmt seed -- sfmt )
+    [ [ state>> ] dip >>seed drop ]
+    [ drop init-sfmt ] 2bi ;
+
 : <sfmt-19937> ( seed -- sfmt )
     348 330 uint-4{ HEX: BFFFFFF6 HEX: BFFAFFFF HEX: DDFECB7F HEX: DFFFFFEF }
     <sfmt> ; inline

        swap >>seed
        0 >>ix ;

: <sfmt> ( seed n m mask -- sfmt )
    <sfmt-state>
    sfmt new
        swap >>state
        dup <sfmt-array> [ >>uint-array ] [ >>uint-4-array ] bi*
        [ generate ] keep ; inline

: refill-sfmt? ( sfmt -- ? )
    state>> [ ix>> ] [ n>> 4 * ] bi >= ;

    { r2 uint-4 } ;

TUPLE: sfmt
    { state sfmt-state }
    { uint-array uint-array }
    { uint-4-array uint-4-array } ;

: wA ( w -- wA )
   dup 1 hlshift vbitxor ; inline
