random-seed

How to mimic rand() function of C in python?

How to mimic rand() function of C in python? Question: I am trying to reverse a logic of a C program with python. Part of the C program is the following : timeVar = time((time_t *)0x0) seed = (uint)timeVar; srand(seed); random_value1 = rand(); random_value2 = rand(); random_value3 = rand(); There is no upper bound given …

Total answers: 3

Random dont chose 8 character words

Random dont chose 8 character words Question: I used random module in my ptoject. Im not a programmer, but i need to do a script which will create a randomized database from another database. In my case, I need the script to select random words lined up in a column from the "wordlist.txt" file, and …

Total answers: 1

Using SeedSequence to convert any random seed into a good seed

Using SeedSequence to convert any random seed into a good seed Question: In NumPy 1.17, the random module was given an overhaul. Among the new additions were SeedSequence. In the section about parallel random number generation in the docs, SeedSequence is said to ensure that low-quality seeds are turned into high quality initial states which …

Total answers: 1

Tensorflow's random.truncated_normal returns different results with the same seed

Tensorflow's random.truncated_normal returns different results with the same seed Question: The following lines are supposed to get the same result: print (tf.random.truncated_normal(shape=[2],seed=1234)) print (tf.random.truncated_normal(shape=[2],seed=1234)) But I got: tf.Tensor([-0.12297685 -0.76935077], shape=(2,), dtype=float32) tf.Tensor([0.37034193 1.3367208 ], shape=(2,), dtype=float32) Why? Asked By: zell || Source Answers: This seems to be intentional, see the docs here. Specifically the "Examples" …

Total answers: 2

Is it possible to change the seed of a random generator in NumPy?

Is it possible to change the seed of a random generator in NumPy? Question: Say I instantiated a random generator with import numpy as np rng = np.random.default_rng(seed=42) and I want to change its seed. Is it possible to update the seed of the generator instead of instantiating a new generator with the new seed? …

Total answers: 2

`random.seed` doesn't work with generators

`random.seed` doesn't work with generators Question: I have a function that generates a sequence of random integers using random.randint. I also include a seed parameter for reproducibility. I noticed an odd behavior when I returned a generator object. Different calls with the same seed did not return the same result. However, when I returned a …

Total answers: 1

A random seed that makes tests fail the same way every time?

A random seed that makes tests fail the same way every time? Question: I’ve never worked with the random library and I’m a bit confused about what this fixme statement is asking me to do. Is there a seed number that specifically does this? The code is making an ordered list ADT and this file …

Total answers: 3

Why im getting 2 different results on the same seed number?

Why im getting 2 different results on the same seed number? Question: I tried two different ways to get a coin flip result, seeding the RNG first in order to get reproducible results. First, I tried using random.randint: import random random.seed(23412) flip = random.randint(0,1) if flip == 0: print("Tails") else: print("Heads") For this seed, I …

Total answers: 2

How does the random.seed function in python work for words? What number is it converted to?

How does the random.seed function in python work for words? What number is it converted to? Question: I realized that if I choose random.seed("hello world!") it actually works, i.e. it does not give me any error and it works like a normal seed; So for example choosing random.seed("hello world!") random.choices([1,2,3,4,5,6,7], k = 10) keeps giving …

Total answers: 1

np.random.rand() or random.random()

np.random.rand() or random.random() Question: While analyzing a code, I’ve stumbled upon the following snippet: msk = np.random.rand(len(df)) < 0.8 Variables "msk" and "df" are irrelevant for my question. After doing some research I think this usage is also related to "random" class as well. It gives True with 80% chance and False with 20% chance …

Total answers: 1