random-seed

Isolate randomness of a local environment from the global R process

故事扮演 提交于 2019-12-22 04:15:17
问题 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 by the global seed runif(1) } f() # [1] 0.8966972 Basically I want to be able to avoid the effect of the global random seed (i.e., .Random.seed ) in a local environment, such as an R function, so that I can achieve some sort of randomness over which

Random number from a seed

♀尐吖头ヾ 提交于 2019-12-22 03:22:37
问题 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

Set seed on Math.random()

冷暖自知 提交于 2019-12-21 10:16:06
问题 I need to write some junit tests on Java code that calls Math.random() . I know that I can set the seed if I was instantiating my own Random object to produce repeatable results. Is there a way to do this also for Math.random() ? 回答1: The method Math.random() uses a private static field: private static Random randomNumberGenerator; If you really really need to set this to a new Random(CONSTANT_SEED) (for instance you need to JUNit test code which you have no control over) you could do so by

Set seed on Math.random()

孤人 提交于 2019-12-21 10:15:59
问题 I need to write some junit tests on Java code that calls Math.random() . I know that I can set the seed if I was instantiating my own Random object to produce repeatable results. Is there a way to do this also for Math.random() ? 回答1: The method Math.random() uses a private static field: private static Random randomNumberGenerator; If you really really need to set this to a new Random(CONSTANT_SEED) (for instance you need to JUNit test code which you have no control over) you could do so by

Is seeding data with fixtures dangerous in Ruby on Rails

隐身守侯 提交于 2019-12-20 12:28:43
问题 I have fixtures with initial data that needs to reside in my database (countries, regions, carriers, etc.). I have a task rake db:seed that will seed a database. namespace :db do desc "Load seed fixtures (from db/fixtures) into the current environment's database." task :seed => :environment do require 'active_record/fixtures' Dir.glob(RAILS_ROOT + '/db/fixtures/yamls/*.yml').each do |file| Fixtures.create_fixtures('db/fixtures/yamls', File.basename(file, '.*')) end end end I am a bit worried

Does one need to call srand() C function per thread or per process to seed the randomizer?

杀马特。学长 韩版系。学妹 提交于 2019-12-19 05:24:04
问题 The caption pretty much says it. PS. This is for C++ Windows program. 回答1: According to the MSDN documentation on srand() (assuming you are using Microsoft's C runtime library), the seed is thread-local, so you need to call srand() for each thread that is using rand() . Note that this may not be the case in other implementations. Quoting from MSDN: The srand function sets the starting point for generating a series of pseudorandom integers in the current thread. 回答2: Even if the answer weren't

Is there a way to generate a seed out of a sequence of numbers?

喜夏-厌秋 提交于 2019-12-18 15:32:59
问题 For example if java produces the pseudorandom sequence: 9 3 2 5 6 by using 23 as a seed, how can I do the inverse? i.e. getting 23 out of the sequence 9 3 2 5 6 . Or how do I assign a seed for a certain sequence? It is easy to do if there is a database - just assign a random key for the sequence INSERT INTO SEQUENCE_TABLE VALUES (RANDOM_KEY, SEQUENCE) However if I'm not permitted to use a database, Is there a formula to do such a thing? 回答1: The point of random number generators is that this

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

天大地大妈咪最大 提交于 2019-12-17 06:13:31
问题 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. This seems to produce the same values for a good number of the instances in their random number generation, which uses a time-seed. Is there a simple alternative I can use instead? Reproducibility and security are not important, quick generation of

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

廉价感情. 提交于 2019-12-17 06:12:53
问题 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. This seems to produce the same values for a good number of the instances in their random number generation, which uses a time-seed. Is there a simple alternative I can use instead? Reproducibility and security are not important, quick generation of

random.seed(): What does it do?

。_饼干妹妹 提交于 2019-12-16 20:12:33
问题 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, 10) 6 >>> random.randint(1, 10) 6 >>> random.randint(1, 10) 7 I couldn't find good documentation on this. 回答1: Pseudo-random number generators work by performing some operation on a value. Generally this value is the previous number generated by the