Questions tagged [random-seed]

A random-seed is used to initialize a pseudo-random number generator in many programming languages.

937 questions
8
votes
1 answer

Python: where is random.random() seeded?

Say I have some python code: import random r=random.random() Where is the value of r seeded from in general? And what if my OS has no random, then where is it seeded? Why isn't this recommended for cryptography? Is there some way to know what the…
Academiphile
  • 1,434
  • 2
  • 13
  • 21
8
votes
2 answers

Isolate randomness of a local environment from the global R process

We can use set.seed() to set a random seed in R, and this has a global effect. Here is a minimal example to illustrate my goal: set.seed(0) runif(1) # [1] 0.8966972 set.seed(0) f <- function() { # I do not want this random number to be affected…
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
8
votes
1 answer

What is the effective seed range for Ruby's rand?

Ruby implements PRNGs as "a modified Mersenne Twister with a period of 2**19937-1." 1 The way I understand MT is that it operates on 2^32 different seeds. What confuses me is that Random.new(seed) accepts arbitrarily big numbers such as…
randomguy
  • 12,042
  • 16
  • 71
  • 101
7
votes
1 answer

Results not reproducible between runs despite seeds being set

How is it possible, that running the same Python program twice with the exact same seeds and static data input produces different results? Calling the below function in a Jupyter Notebook yields the same results, however, when I restart the kernel,…
Dreana
  • 573
  • 4
  • 16
7
votes
1 answer

Why does the importance parameter influence performance of Random Forest in R?

When using random forests in R I came across the following situation: library(randomForest) set.seed(42) data(iris) rf_noImportance <-…
Tinu
  • 2,432
  • 2
  • 8
  • 20
7
votes
2 answers

Not able to reproduce results with Tensorflow even with random seed

I am training a simple autoencoder in Keras with data I have generated. I am currently running the code inside a Google Colab notebook (in case there is a small chance that might be relevant). To achieve reproducible results, I am currently setting…
Jane Sully
  • 3,137
  • 10
  • 48
  • 87
7
votes
4 answers

C++ need a good technique for seeding rand() that does not use time()

I have a bash script that starts many client processes. These are AI game players that I'm using to test a game with many players, on the order of 400 connections. The problem I'm having is that the AI player uses srand( time(nullptr) ); But if…
Eyelash
  • 1,760
  • 2
  • 12
  • 18
7
votes
1 answer

Python: dangers of temporarily changing the random seed using a context manager?

When aiming for reproducibility in Python code using random number generators, the recommended approach seems to be to construct separate RandomState objects. Unfortunately, some essential packages like scipy.stats cannot (to the best of my…
Bonnevie
  • 187
  • 9
7
votes
1 answer

How to use random.RandomState

I'd like my script to create the same array of numbers each time I run the script. Earlier I was using np.random.seed(). For example: np.random.seed(1) X = np.random.random((3,2)) I've read that instead of np.random.seed() there should be used…
kujaw
  • 313
  • 1
  • 3
  • 18
7
votes
7 answers

c++ generate a good random seed for psudo random number generators

I am trying to generate a good random seed for a psudo-random number generator. I thought I'd get the expert's opinions. let me know if this is a bad way of doing it or if there are much better ways. #include #include #include…
posop
  • 511
  • 2
  • 7
  • 17
7
votes
2 answers

Deterministic random number generation across systems

I need to send an identical sequence of random numbers to a distributed network of applications. Since such sequence might be quite long, I was thinking about sending just a (randomly generated) centralized seed initialization number and the length…
Andrea
  • 884
  • 1
  • 10
  • 23
7
votes
5 answers

Seeding rand() for a C++ class

I am working on a C++ class that uses a rand() in the constructor. I would really like for this class to take care of itself in pretty much every way, but I'm not sure where to seed rand(). If I seed rand() in the constructor, it will be seeded…
Alex
  • 671
  • 3
  • 11
  • 25
6
votes
3 answers

generating random numbers in C++ using TR1 /dev/random (resilient to <1 second runs)

I would like to generate uniform random numbers in C++ between 0 and 1, in a way which does not use the standard rand() and srand(time(NULL)) method. The reason for this is that if I run the application more than once within the same second of my…
gnychis
  • 7,289
  • 18
  • 75
  • 113
6
votes
2 answers

Initialize random number generator in ruby (i.e. set seed)?

How can we set a seed in ruby such that any functions dependent on RNG return the same results (e.g. similar to python's random.seed() ?
dss
  • 395
  • 3
  • 11
6
votes
1 answer

How to use Pytest to test functions that generate random samples?

Lets say I generate some input numpy array data using a np.random.normal() in my test_func.py script that is using pytest. Now I want to call the func.py function that I am testing. How am I able to get testable results? If I set a seed in the…
Coldchain9
  • 1,373
  • 11
  • 31