Questions tagged [random-seed]

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

937 questions
568
votes
21 answers

Seeding the random number generator in Javascript

Is it possible to seed the random number generator (Math.random) in JavaScript?
weepy
  • 6,181
  • 4
  • 20
  • 10
224
votes
12 answers

random.seed(): What does it do?

I am a bit confused on what random.seed() does in Python. For example, why does the below trials do what they do (consistently)? >>> import random >>> random.seed(9001) >>> random.randint(1, 10) 1 >>> random.randint(1, 10) 3 >>> random.randint(1,…
Ahaan S. Rungta
  • 2,323
  • 2
  • 12
  • 15
205
votes
9 answers

Is java.util.Random really that random? How can I generate 52! (factorial) possible sequences?

I've been using Random (java.util.Random) to shuffle a deck of 52 cards. There are 52! (8.0658175e+67) possibilities. Yet, I've found out that the seed for java.util.Random is a long, which is much smaller at 2^64 (1.8446744e+19). From here, I'm…
Sergey Emeliyanov
  • 5,158
  • 6
  • 29
  • 52
130
votes
4 answers

Differences between numpy.random and random.random in Python

I have a big script in Python. I inspired myself in other people's code so I ended up using the numpy.random module for some things (for example for creating an array of random numbers taken from a binomial distribution) and in other places I use…
Laura
  • 1,822
  • 3
  • 15
  • 23
97
votes
6 answers

How can I retrieve the current seed of NumPy's random number generator?

The following imports NumPy and sets the seed. import numpy as np np.random.seed(42) However, I'm not interested in setting the seed but more in reading it. random.get_state() does not seem to contain the seed. The documentation doesn't show an…
Mast
  • 1,788
  • 4
  • 29
  • 46
70
votes
1 answer

Should I use `random.seed` or `numpy.random.seed` to control random number generation in `scikit-learn`?

I'm using scikit-learn and numpy and I want to set the global seed so that my work is reproducible. Should I use numpy.random.seed or random.seed? From the link in the comments, I understand that they are different, and that the numpy version is not…
shadowtalker
  • 12,529
  • 3
  • 53
  • 96
65
votes
5 answers

Can I get.seed() somehow?

In reference to the statement set.seed(), can I get the seed instead after running some code if I didn't set it explicitly? I've been re-running some code (interactively / at the console) containing a function that randomises some sample of the…
a different ben
  • 3,900
  • 6
  • 35
  • 45
35
votes
7 answers

How do I get the seed from a Random in Java?

I am creating a deep clone for some object. The object contains a Random. Is it good practice to retrieve the seed from the Random? If so, how? There isn't a Random.getSeed().
Marnix
  • 6,384
  • 4
  • 43
  • 78
34
votes
2 answers

Inconsistent results for f(g(x)) together or split up

During a recent investigation into setting random seeds within functions, I came across an odd situation. Consider functions f and g, each of which sets the random seed and then performs a simple randomized operation: g <- function(size) {…
josliber
  • 43,891
  • 12
  • 98
  • 133
33
votes
10 answers

Is there an alternative to using time to seed a random number generation?

I'm trying to run several instances of a piece of code (2000 instances or so) concurrently in a computing cluster. The way it works is that I submit the jobs and the cluster will run them as nodes open up every so often, with several jobs per node.…
CHP
  • 895
  • 5
  • 13
  • 28
31
votes
6 answers

Best way to seed mt19937_64 for Monte Carlo simulations

I'm working on a program that runs Monte Carlo simulation; specifically, I'm using a Metropolis algorithm. The program needs to generate possibly billions of "random" numbers. I know that the Mersenne twister is very popular for Monte Carlo…
Mathhead200
  • 331
  • 1
  • 3
  • 6
29
votes
3 answers

Is set.seed consistent over different versions of R (and Ubuntu)?

I am currently running R version 3.1.0 (on Ubuntu 12.04 LTS) and as both my R version and my operating system is getting rather old, I plan on updating both. However, I have a lot of simulations that rely on set.seed() and I would like them to still…
Phil
  • 595
  • 1
  • 5
  • 15
28
votes
6 answers

Swift 4.2+ seeding a random number generator

I'm trying to generate seeded random numbers with Swift 4.2+, with the Int.random() function, however there is no given implementation that allows for the random number generator to be seeded. As far as I can tell, the only way to do this is to…
RPatel99
  • 7,448
  • 2
  • 37
  • 45
28
votes
4 answers

How do I stop set.seed() after a specific line of code?

I would like to end the scope of set.seed() after a specific line in order to have real randomization for the rest of the code. Here is an example in which I want set.seed() to work for "rnorm" (line 4), but not for "nrow" (line 9)…
Clyde Frog
  • 483
  • 1
  • 6
  • 15
28
votes
1 answer

What is the scope of a random seed in Python?

If I use the Python function random.seed(my_seed) in one class in my module, will this seed remain for all the other classes instantiated in this module?
Lyrositor
  • 383
  • 4
  • 7
1
2 3
62 63