random-seed

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

假装没事ソ 提交于 2019-12-10 02:12:02
问题 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) set.seed(2014) f<-function(x){0.5*x+2} datax<-1:100 datay<-f(datax)+rnorm(100,0,5) daten<-data.frame(datax,datay) model<-lm(datay~datax) plot(datax,datay) abline(model) a<-daten[sample(nrow(daten),20),] points(a,col="red",pch=16) modela<-lm(a$datay~a$datax) abline

Where can I get a reliable source of entropy (real randomness byte[])?

亡梦爱人 提交于 2019-12-08 02:01:25
问题 Currently, I'm looking for a way to increase the quality of randomness in my Android application (a card game). Previously, it was estimated that for my situation (52! permutation) at least 226 bits of entropy (226 random bits) are needed.. I'm planning to use this byte[] as a seed for SecureRandom : SecureRandom random = new SecureRandom(); random.setSeed(/* insert seed here, byte[] */) The question is -- Where can I reliably get random bits in this amount (at least 226 bits) on Android ,

Is there're a way to seed Swift 4.2 random number generator

Deadly 提交于 2019-12-07 08:40:54
问题 I like the new Swift 4.2 RandomNumberGenerator thing, but I don't see a seed possibility there. Am I missing something, or is there any way at all to seed these generators, by maybe calling an underlying low-level function? I have a lot of code, which uses default number generators on default number types, and I now need to make sure that everything behaves exactly the same between launches with as little code changes as possible. 回答1: The whole idea of the new architecture is that any

Is hash() randomization considered cryptographically strong?

最后都变了- 提交于 2019-12-06 12:08:18
问题 Starting from the CPython 3.3, hash randomization is enabled by default. On previous versions it could be turned on by specifying the -R command-line option or by setting the PYTHONHASHSEED environment variable to random . Citing the documentation: By default, the __hash__() values of str, bytes and datetime objects are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python

Where can I get a reliable source of entropy (real randomness byte[])?

情到浓时终转凉″ 提交于 2019-12-06 08:10:58
Currently, I'm looking for a way to increase the quality of randomness in my Android application (a card game). Previously, it was estimated that for my situation (52! permutation) at least 226 bits of entropy (226 random bits) are needed.. I'm planning to use this byte[] as a seed for SecureRandom : SecureRandom random = new SecureRandom(); random.setSeed(/* insert seed here, byte[] */) The question is -- Where can I reliably get random bits in this amount (at least 226 bits) on Android , preferably without requiring any permissions and without internet. Also, it should work regardless of

Is there're a way to seed Swift 4.2 random number generator

北慕城南 提交于 2019-12-05 13:21:45
I like the new Swift 4.2 RandomNumberGenerator thing, but I don't see a seed possibility there. Am I missing something, or is there any way at all to seed these generators, by maybe calling an underlying low-level function? I have a lot of code, which uses default number generators on default number types, and I now need to make sure that everything behaves exactly the same between launches with as little code changes as possible. The whole idea of the new architecture is that any generator can be substituted just by adopting the RandomNumberGenerator protocol. So if you need a repeatable seed

Random number from a seed

梦想的初衷 提交于 2019-12-04 23:38:35
I have an application where it becomes extremely noticeable if my program uses an RNG that has patterns based on its seed, as it builds landscapes based on the x coordinate of the landscape. While Random works well if you're calling Next() every time, I need to be able to have the same output every time I use the same input, and thus can't rely on Next() . Instead, I attempted to simply make a new Random every time with the input seed. Not a very good idea, I know, and it showed. The patterns were extremely obvious, with alternating high and low values, and an noticeable overall trend across

Difference between Python 2 and 3 for shuffle with a given seed

时光总嘲笑我的痴心妄想 提交于 2019-12-04 06:15:40
I am writing a program compatible with both Python 2.7 and 3.5. Some parts of it rely on stochastic process. My unit tests use an arbitrary seed, which leads to the same results across executions and languages... except for the code using random.shuffle . Example in Python 2.7: In[]: import random random.seed(42) print(random.random()) l = list(range(20)) random.shuffle(l) print(l) Out[]: 0.639426798458 [6, 8, 9, 15, 7, 3, 17, 14, 11, 16, 2, 19, 18, 1, 13, 10, 12, 4, 5, 0] Same input in Python 3.5: In []: import random random.seed(42) print(random.random()) l = list(range(20)) random.shuffle(l

generate random number in c++

梦想的初衷 提交于 2019-12-04 04:49:49
问题 I get a task to generate tens of thousands random number in c++. I've googled a lot about random number in c++ and look up the c++ reference, but I got confused now. As I know, random_device is a non-deterministic random number generator, but every time I re-run my program, the random number generated by random_device is the same. So how do I set a seed for random_device to make the random number is different when I restart my program? And I've read that "std::random_device could run out of

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

眉间皱痕 提交于 2019-12-03 18:38:05
问题 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 obvious answer. How do I retrieve the current seed used by numpy.random , assuming I did not set it manually? I want to use the current seed to carry over for the next iteration of a process. 回答1: The short answer is that you simply can't (at least not