A fast (pseudo)-random number generator.

    Parameters
    ----------
    state: array of int64, shape (3,)
        The internal state of the rng

    Returns
    -------
    A (pseudo)-random int32 value
179521
def tau_rand_int(state):
    
    state[0] = (((state[0] & 4294967294) << 12) & 0xffffffff) ^ (
        (((state[0] << 13) & 0xffffffff) ^ state[0]) >> 19
    )
    state[1] = (((state[1] & 4294967288) << 4) & 0xffffffff) ^ (
        (((state[1] << 2) & 0xffffffff) ^ state[1]) >> 25
    )
    state[2] = (((state[2] & 4294967280) << 17) & 0xffffffff) ^ (
        (((state[2] << 3) & 0xffffffff) ^ state[2]) >> 11
    )

    return state[0] ^ state[1] ^ state[2]
552671
def random(self, n: Optional[int] = None) -> Union[List[float], float]:
        
        randoms = []
        n_or_default = 1 if n is None else n

        for _ in range(n_or_default):
            number_of_digits = _RandintsToFloatOptions.RANDINTS_NUMBER_OF_DIGITS.value
            max_int = int('9' * number_of_digits)

            randints = self.randint(0, max_int, _RandintsToFloatOptions.RANDINTS_QUANTITY.value)
            zero_padded_ints = (str(randint).zfill(number_of_digits) for randint in randints)
            random = float(f"0.{''.join(zero_padded_ints)}")
            randoms.append(random)

        return randoms if n else randoms[0]
629231
def ancestral_states(self, n):
        
        anc = np.empty(n, dtype=np.intc)
        _weighted_choices(self.state_indices, self.freqs, anc)
        return anc
617351
def random(self, shape, tf_fn, kwargs):
    
    # TODO(noam): can we make things better with stateless_random?
    slice_shape = self.slice_shape(shape)
    x = tf_fn(slice_shape, **kwargs)
    # TPU does not have seeds enabled.  Sync up the
    # random choices by zeroing out all but the first core per group of
    # identical slices, then allreducing by group.
    layout = self.tensor_layout(shape)
    # we need to sync across these axes.
    mesh_axes = [i for i in xrange(self.ndims)
                 if i not in layout.tensor_axis_to_mesh_axis]
    multiplier = 1.0
    for axis in mesh_axes:
      multiplier *= tf.cast(
          tf.equal(self.laid_out_pcoord(axis).one_slice, 0), x.dtype)
    x *= multiplier
    x = self.LaidOutTensor([x])
    x = self.allreduce(x, mesh_axes, "SUM")
    return x
1023246
def random_rotation():
        
        rand_seed = np.random.rand(3, 3)
        U, S, V = np.linalg.svd(rand_seed)
        return U
355024
def _generate_state(self, trans):
        
        state = PDAState()
        state.id = self.nextstate()
        state.type = 2
        state.sym = state.id
        state.trans = trans.copy()
        self.toadd.append(state)
        return state.id
124872
def run(self, state: Any) -> Tuple[Any, Any]:
        
        return self._value(state)
1101675
def _states(self, state, processedstates=[]): #pylint: disable=dangerous-default-value
        """"""
        processedstates.append(state)

        for nextstate in state.epsilon:
            if not nextstate in processedstates:
                self._states(nextstate, processedstates)

        for _, nextstate in state.transitions:
            if not nextstate in processedstates:
                self._states(nextstate, processedstates)

        return processedstates
699656
def _generate_state_token(self, length=32):
        
        choices = ascii_letters + digits
        return ''.join(SystemRandom().choice(choices) for _ in range(length))
1065244
def forward_state(self, sequence, state=None):
        
        if state is None:
            state = self.zero_state(sequence.size(0))

        data = self.input_block(sequence)

        state_outputs = []

        # for layer_length, layer in zip(self.hidden_layers, self.recurrent_layers):
        for idx in range(len(self.recurrent_layers)):
            layer_length = self.recurrent_layers[idx].state_dim

            # Partition hidden state, for each layer we have layer_length of h state and layer_length of c state
            current_state = state[:, :, :layer_length]
            state = state[:, :, layer_length:]

            # Propagate through the GRU state
            data, new_h = self.recurrent_layers[idx](data, current_state)

            if self.dropout_layers:
                data = self.dropout_layers[idx](data)

            state_outputs.append(new_h)

        output_data = self.output_activation(self.output_layer(data))

        concatenated_hidden_output = torch.cat(state_outputs, dim=2)

        return output_data, concatenated_hidden_output
1352544
def gen(self, init_state=None):
        
        state = init_state or (BEGIN,) * self.state_size
        while True:
            next_word = self.move(state)
            if next_word == END: break
            yield next_word
            state = tuple(state[1:]) + (next_word,)
409569
def p_state(self, state):
        ''''''
        state[0] = State(state[1][0], state[1][1], state[1][2], state[1][3], state[2])
1171845
def _random_block():
    
    # TODO: Use a better RNG than random.randint
    random_number = random.randint(0, DISCRETE_VALUES)
    random_string = _to_base36(random_number)
    return _pad(random_string, BLOCK_SIZE)
778566
def randint(self, a: int, b: int, n: Optional[int] = None) -> Union[List[int], int]:
        
        max_n = self.config.MAX_NUMBER_OF_INTEGERS
        return self._generate_randoms(self._request_randints, max_n=max_n, a=a, b=b, n=n)
547047
def random(self):
        
        return '#' + random.randrange(256).encode('hex') + \
               random.randrange(256).encode('hex') + random.randrange(256).encode('hex')
437868
def random_integers(cls, size, seed=None):
        
        if seed is None:
            seed = abs(hash("%0.20f" % time.time())) % (2 ** 31)
        return cls.from_sequence(size).hash(seed)
800653
def loguniform(low, high, random_state):
    '''
    
    '''
    assert low > 0, 'Lower bound must be positive'
    return np.exp(uniform(np.log(low), np.log(high), random_state))