How to generate random number using multiple seed values?
Date : March 29 2020, 07:55 AM
should help you out Assuming you always need the same seed every time for the set of coordinates: just encrypt a concated string with MD5 or some other hash algorithm. md5("1,2,3") is not the same as md5("3,2,1"). Or if you need a purely numeric string, use something like: "first digit * 9" + "second digit * 8" + "third digit * 7" that will give you more variety. If you don't, use the above methods with a random number.
|
Generate multiple independent random streams in python
Tag : python , By : Mario Tristan
Date : March 29 2020, 07:55 AM
This might help you Both Numpy and the internal random generators have instantiatable classes. For just random: import random
random_generator = random.Random()
random_generator.random()
#>>> 0.9493959884174072
import numpy
random_generator = numpy.random.RandomState()
random_generator.uniform(0, 1, 10)
#>>> array([ 0.98992857, 0.83503764, 0.00337241, 0.76597264, 0.61333436,
#>>> 0.0916262 , 0.52129459, 0.44857548, 0.86692693, 0.21150068])
|
Should I use `random.seed` or `numpy.random.seed` to control random number generation in `scikit-learn`?
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm using scikit-learn and numpy and I want to set the global seed so that my work is reproducible. , Should I use np.random.seed or random.seed?
|
Making functions that set the random seed independent
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I've dug into this some more and it looks like the rlecuyer package provides independent random streams: library(rlecuyer)
.lec.CreateStream(c("stream.12", "stream.prod"))
sample.12 <- function(size) {
.lec.ResetStartStream("stream.12")
.lec.CurrentStream("stream.12")
x <- sample(1:2, size, replace=TRUE)
.lec.CurrentStreamEnd()
x
}
rand.prod <- function(x) {
.lec.ResetStartStream("stream.prod")
.lec.CurrentStream("stream.prod")
y <- runif(length(x)) * x
.lec.CurrentStreamEnd()
y
}
all.equal(rand.prod(sample.12(10000)), rand.prod(sample.12(10000)))
# [1] TRUE
x <- sample.12(10000)
hist(rand.prod(x))
.lec.GetState("stream.12")
# [1] 3161578179 1307260052 2724279262 1101690876 1009565594 836476762
.lec.GetState("stream.prod")
# [1] 596094074 2279636413 3050913596 1739649456 2368706608 3058697049
library(rlecuyer)
.lec.CreateStream(c("stream.12", "stream.prod"))
.lec.SetSeed("stream.12", c(3161578179, 1307260052, 2724279262, 1101690876, 1009565594, 836476762))
.lec.SetSeed("stream.prod", c(596094074, 2279636413, 3050913596, 1739649456, 2368706608, 3058697049))
|
Do consequtive RNG seed yield independent random numbers?
Date : March 29 2020, 07:55 AM
|