Creates pseudo-number generator

    :param seed: seeder
    :param amount: amount of number to generate
    :param prime0: one prime number
    :param prime1: the second prime number
    :return: pseudo-number generator
17789
def blum_blum_shub(seed, amount, prime0, prime1):
    
    if amount == 0:
        return []

    assert (prime0 % 4 == 3 and
            prime1 % 4 == 3)  # primes must be congruent 3 mod 4

    mod = prime0 * prime1
    rand = [seed]

    for _ in range(amount - 1):
        last_num = rand[len(rand) - 1]
        next_num = (last_num * last_num) % mod
        rand.append(next_num)

    return rand
412685
synchronized public void setSeed(final long seed)
        {
        // Due to a bug in java.util.Random clear up to 1.2, we're
        // doing our own Gaussian variable.
        __haveNextNextGaussian = false;

        mt = new int[N];
        
        mag01 = new int[2];
        mag01[0] = 0x0;
        mag01[1] = MATRIX_A;

        mt[0]= (int)(seed & 0xffffffff);
        for (mti=1; mti<N; mti++) 
            {
            mt[mti] = 
                (1812433253 * (mt[mti-1] ^ (mt[mti-1] >>> 30)) + mti); 
            /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
            /* In the previous versions, MSBs of the seed affect   */
            /* only MSBs of the array mt[].                        */
            /* 2002/01/09 modified by Makoto Matsumoto             */
            mt[mti] &= 0xffffffff;
            /* for >32 bit machines */
            }
        }
802237
def initialize_path(self, path_num=None):
        
        for p in self.producers:
            p.initialize_path(path_num)
        # self.state = copy(self.initial_state)
        # self.state.path = path_num
        self.random.seed(hash(self.seed) + hash(path_num))
38111
def scenarios(self, generate_seed=False):
        
        seed = prime_numbers(1000)
        sweeps_all = self.experiment["sweeps"].keys()
        if "combinations" in self.experiment:
            if isinstance(self.experiment["combinations"], list):
                # For backward compatibility with experiments1-4s
                combinations_in_experiment = {" ": self.experiment["combinations"]}
                # if self.experiment["combinations"] == []:
                #    # Special notation for fully-factorial experiments
                #    combinations_in_experiment = {" ":[[],[]]}
            else:
                # Combinations must be a dictionary in this particular case
                combinations_in_experiment = self.experiment["combinations"]
        else:
            # Support no combinations element:
            combinations_in_experiment = dict()    # empty dict 

        # 1) calculate combinations_sweeps (depends on ALL combinations_ items)
        # Get the list of fully factorial sweeps
        all_combinations_sweeps = []
        all_combinations = []
        for key, combinations_ in combinations_in_experiment.items():
            # generate all permutations of all combinations
            if not combinations_:
                # Fully factorial experiment, shortcut for "combinations":[[],[]]
                combinations_sweeps = []
                combinations = [[]]
            else:
                # First item in combinations list is a list of sweeps
                combinations_sweeps = combinations_[0]
                # then - all combinations
                combinations = combinations_[1:]
            for item in combinations_sweeps:
                # TODO: error if sweep is already in this list?
                all_combinations_sweeps.append(item)
            all_combinations.append((combinations_sweeps, combinations))
        
        sweeps_fully_factorial = list(set(sweeps_all) - set(all_combinations_sweeps))
        # print "fully fact: %s" % sweeps_fully_factorial
        
        # 2) produce a list of all combinations of fully factorial sweeps
        # First sets of "combinations": the fully-factorial sweeps
        for sweep in sweeps_fully_factorial:
            all_combinations.append(([sweep], [[x] for x in self.experiment["sweeps"][sweep].keys()]))
        
        # 3) take the dot (inner) product of the list above (fully factorial arm combinations)
        #   with the first combinations list, that with the second combination list, ...
        # step-by-step reduce the list of combinations to a single item
        # (dot-product of each list of combinations)
        # this could use a lot of memory...
        red_iter = 0
        # print "all combinations:", red_iter, all_combinations
        while len(all_combinations) > 1:
            comb1 = all_combinations[0]
            comb2 = all_combinations[1]
            new_sweeps = comb1[0] + comb2[0]
            new_combinations = [x+y for x in comb1[1] for y in comb2[1]]
            all_combinations = [(new_sweeps, new_combinations)] + all_combinations[2:]
            red_iter += 1
            # print "all combinations:", red_iter, all_combinations
        
        # 4) write out the document for each in (3), which should specify one arm for each
        #   sweep with no repetition of combinations
        sweep_names = all_combinations[0][0]
        combinations = all_combinations[0][1]
        for combination in combinations:
            scenario = Scenario(self._apply_combination(self.experiment["base"], sweep_names, combination))
            scenario.parameters = dict(zip(sweep_names, combination))

            if generate_seed:
                # Replace seed if requested by the user
                if "@seed@" in scenario.xml:
                    scenario.xml = scenario.xml.replace("@seed@", str(next(seed)))
                else:
                    raise(RuntimeError("@seed@ placeholder is not found"))
            yield scenario
703615
def resample(self, seed=None):
        
        if seed is not None:
            gen = torch.manual_seed(seed)
        else:
            gen = torch.default_generator

        if self.replacement:
            self.perm = torch.LongTensor(len(self)).random_(
                len(self.dataset), generator=gen)
        else:
            self.perm = torch.randperm(
                len(self.dataset), generator=gen).narrow(0, 0, len(self))
97478
def set_seed(seed: int):
    
    random.seed(seed)
    np.random.seed(seed)
    torch.random.manual_seed(seed)
990006
def initialize(self, grid, num_of_paths, seed):
        
        for p in self.producers:
            p.initialize(grid, num_of_paths, seed)
        self.grid = grid
        self.num_of_paths = num_of_paths
        self.seed = seed
66231
def set_seed(self, seed):

        

        assert seed.dtype == np.int and seed.shape == (self.samples, self.N)
        self.topic_seed = seed
959501
def _findNextPrime(self, N):
        """"""
        primes = self.primes
        nextPrime = primes[-1]+1
        while(len(primes)<N):
            maximum = nextPrime * nextPrime
            prime = 1
            for i in primes:
                if i > maximum:
                    break
                if nextPrime % i == 0:
                    prime = 0
                    break
            if prime:
                primes.append(nextPrime)
            nextPrime+=1
642373
def make(self, pnum):
        
        try:
                
            # Create the PID file
            self.mkfile(self.pid_file, pnum)
        except Exception as e:
            self.die('Failed to generate PID file: {}'.format(str(e)))
40282
def _factor_generator(n):
    
    p = prime_factors(n)
    factors = {}
    for p1 in p:
        try:
            factors[p1] += 1
        except KeyError:
            factors[p1] = 1
    return factors
61985
def create_primes(threshold):
    
    if threshold == 2:
        return [2]

    elif threshold < 2:
        return []

    numbers = list(range(3, threshold+1, 2))
    root_of_threshold = threshold ** 0.5
    half = int((threshold+1)/2-1)
    idx = 0
    counter = 3
    while counter <= root_of_threshold:
        if numbers[idx]:
            idy = int((counter*counter-3)/2)
            numbers[idy] = 0
            while idy < half:
                numbers[idy] = 0
                idy += counter
        idx += 1
        counter = 2*idx+3
    return [2] + [number for number in numbers if number]
482315
private final void setSeed(int seed) {

		// Annoying runtime check for initialisation of internal data
		// caused by java.util.Random invoking setSeed() during init.
		// This is unavoidable because no fields in our instance will
		// have been initialised at this point, not even if the code
		// were placed at the declaration of the member variable.
		if (mt == null) mt = new int[N];

		// ---- Begin Mersenne Twister Algorithm ----
		mt[0] = seed;
		for (mti = 1; mti < N; mti++) {
			mt[mti] = (MAGIC_FACTOR1 * (mt[mti-1] ^ (mt[mti-1] >>> 30)) + mti);
		}
		// ---- End Mersenne Twister Algorithm ----
	}
1245704
def seed(self, x=None, *args):
        
        if x is None:
            # Use same random seed code copied from Python's random.Random
            try:
                x = long(_hexlify(_urandom(16)), 16)
            except NotImplementedError:
                import time
                x = long(time.time() * 256) # use fractional seconds
        elif not isinstance(x, _Integral):
            # Use the hash of the input seed object. Note this does not give
            # consistent results cross-platform--between Python versions or
            # between 32-bit and 64-bit systems.
            x = hash(x)
        self.rng_iterator.seed(x, *args, mix_extras=True)
1115211
def get_random_number_generator_and_set_seed(seed=None):
  """"""
  random.seed(seed)
  # While python random accepts None as seed and uses time/os seed then,
  # some other functions expect integers so we create one here.
  if seed is None:
    seed = random.randint(0, 2**31 - 1)
  tf.set_random_seed(seed)
  numpy.random.seed(seed)
  return jax_random.get_prng(seed)
986663
def _check_seed(seed):
    
    if isinstance(seed, (Number, string_types)):
        try:
            seed = int(seed)
        except ValueError:
            logger.warning("`seed` must be castable to an integer")
            seed = None
        else:
            if seed < 0:
                logger.warning("`seed` may not be negative")
                seed = None
            elif seed > MAX_UINT:
                raise ValueError('`seed` is too large; max is {}'.format(MAX_UINT))
    elif isinstance(seed, np.random.RandomState):
        seed = seed.randint(0, MAX_UINT)
    elif seed is not None:
        logger.warning('`seed` has unexpected type')
        seed = None

    if seed is None:
        seed = random.randint(0, MAX_UINT)

    return seed
906029
def expand_seed(self, start_seed, num_iterations, val):
        
        self.grd.set_tile(start_seed[0], start_seed[1], val)
        cur_pos = [start_seed[0], start_seed[1]]
        while num_iterations > 0:   # don't use loop as it will hit boundaries often
            num_iterations -= 1
            for y in range(cur_pos[0]-randint(0,2), cur_pos[0] + randint(0,2)):
                for x in range(cur_pos[1]-randint(0,2), cur_pos[1] + randint(0,2)):
                    if x < self.grd.grid_width and x >= 0 and y >= 0 and y < self.grd.grid_height:
                        #print(x,y,val)
                        if self.grd.get_tile(y,x) != val:
                            self.grd.set_tile(y, x, TERRAIN_LAND)
                            num_iterations -= 1
            new_x = cur_pos[0] + randint(0,3)-2
            new_y = cur_pos[1] + randint(0,3)-2
            if new_x > self.grd.grid_width - 1:
                new_x = 0
            if new_y > self.grd.grid_height - 1:
                new_y = 0
            if new_x < 0:
                new_x = self.grd.grid_width - 1
            if new_y < 0:
                new_y = self.grd.grid_height - 1
            cur_pos = [new_y, new_x]