(self, val)
Reseed the random number generator.
Reseed the random number generator.
Reseed the random number generator .
def reseed(self, val):
        """Reseed the random number generator."""
        # RANDOMIZE converts to int in a non-standard way -
        # looking at the first two bytes in the internal representation
        # on a program line, if a number outside the signed int range (or -32768) is entered,
        # the number is stored as a MBF double or float. Randomize then:
        #   - ignores the first 4 bytes (if it's a double)
        #   - reads the next two
        #   - xors them with the final two (most significant including sign bit, and exponent)
        # and interprets them as a signed int
        # e.g. 1#    = /x00/x00/x00/x00 /x00/x00/x00/x81 gets read as /x00/x00 ^ /x00/x81
        #            = /x00/x81 -> 0x10000-0x8100 = -32512 (sign bit set)
        #      0.25# = /x00/x00/x00/x00 /x00/x00/x00/x7f gets read as /x00/x00 ^ /x00/x7f
        #            = /x00/x7F -> 0x7F00 = 32512 (sign bit not set)
        #              /xDE/xAD/xBE/xEF /xFF/x80/x00/x80 gets read as /xFF/x80 ^ /x00/x80
        #            = /xFF/x00 -> 0x00FF = 255
        s = val.to_bytes()
        final_two = s[-2:]
        mask = bytearray(2)
        if len(s) >= 4:
            mask = s[-4:-2]
        final_two = int2byte(final_two[0]^mask[0]) + int2byte(final_two[1]^mask[1])
        # unpack to signed integer
        n, = struct.unpack('<h', final_two)
        self._seed &= 0xff
        self._cycle()
        self._seed += n * self._step
        self._seed %= self._period
def reseed ( self , val ) : # RANDOMIZE converts to int in a non-standard way - # looking at the first two bytes in the internal representation # on a program line, if a number outside the signed int range (or -32768) is entered, # the number is stored as a MBF double or float. Randomize then: #   - ignores the first 4 bytes (if it's a double) #   - reads the next two #   - xors them with the final two (most significant including sign bit, and exponent) # and interprets them as a signed int # e.g. 1#    = /x00/x00/x00/x00 /x00/x00/x00/x81 gets read as /x00/x00 ^ /x00/x81 #            = /x00/x81 -> 0x10000-0x8100 = -32512 (sign bit set) #      0.25# = /x00/x00/x00/x00 /x00/x00/x00/x7f gets read as /x00/x00 ^ /x00/x7f #            = /x00/x7F -> 0x7F00 = 32512 (sign bit not set) #              /xDE/xAD/xBE/xEF /xFF/x80/x00/x80 gets read as /xFF/x80 ^ /x00/x80 #            = /xFF/x00 -> 0x00FF = 255 s = val . to_bytes ( ) final_two = s [ - 2 : ] mask = bytearray ( 2 ) if len ( s ) >= 4 : mask = s [ - 4 : - 2 ] final_two = int2byte ( final_two [ 0 ] ^ mask [ 0 ] ) + int2byte ( final_two [ 1 ] ^ mask [ 1 ] ) # unpack to signed integer n , = struct . unpack ( '<h' , final_two ) self . _seed &= 0xff self . _cycle ( ) self . _seed += n * self . _step self . _seed %= self . _period