seed

线性同余法的伪随机数

橙三吉。 提交于 2019-11-29 10:29:38
学校练习,简单的我就不放上来了,值得整理的,我保存一下 习题 9 1.1. 伪随机数(线性同余法) 1.1.1.算法描述 我们使用线性同余法,来限定一些离散点在 y=a*x+b 上。 1.1.2. 伪代码 random(n,m,seed,a,b) // 根据现行同余法生成 n 个伪随机书的一个序列 // 输入 : 一个正整数 n 和正整数参数 m,seed,a,b // 输出 : 随机数组 r0<-seed for i<-1 to n do ri<-(a*ri-1+b) mod m end 1.1.3. 算法实现 public static long[] random(int n,int m,long seed,int a,int b){ long[] val=new long[n]; val[0]=seed%m; for(int i=1;i<n;i++) val[i]=(a*val[i-1]+b)%m; return val; } 1.2. 算法小结 使用线性同于法,复杂度 a[n] ,能实现比较类随机的伪随机。 来源: https://www.cnblogs.com/littlepage/p/11515534.html

Possible sources for random number seeds

半腔热情 提交于 2019-11-29 10:29:01
Two points -- first, the example is in Fortran, but I think it should hold for any language; second, the built in random number generators are not truly random and other generators exist, but we're not interested in using them for what we're doing. Most discussions on random seeds acknowledge that if the program doesn't seed it at run-time, then the seed is generated at compile time. So, the same sequence of numbers is generated every time the program is run, which is not good for random numbers. One way to overcome this is to seed the random number generator with the system clock. However,

[Tips] pyton 设置随机种子

你说的曾经没有我的故事 提交于 2019-11-29 09:39:52
对于原生的random模块 import random random.seed(1)    如果不设置,则python根据系统时间自己定一个。 也可以自己根据时间定一个随机种子,如: import time import random seed = int(time.time()) random.seed(seed)    来源: https://www.cnblogs.com/immortalBlog/p/11511162.html

Predict the Seed of Javascript's Math.random

橙三吉。 提交于 2019-11-29 06:54:37
Okay, so I'm doing some research on how random numbers are generated with the Math.random method. So far I learned that it starts with a "random" seed, and that seed is plugged into some complex equation to create a random number. If the seed is always the same, will the outcome always be the same? I heard that the seeds for Math.random are generated through the current time, is that correct? They must use the current time all the way down to the mili-seconds or something, because if you didn't you would get the same outcome. What exactly is the seed? Is it the time such as "10:45" or the time

Undo previously seeded data in Rails

淺唱寂寞╮ 提交于 2019-11-29 06:22:35
I have seeded a row of data to my table by editing db/seed.rb file and executing rake db:seed command. Unknowingly, I put some wrong information in to that row. So I want to remove the previously added row of data. Is there any rake command for the same like rake db:rollback for rake db:migrate . There are a couple of aspects to this: 1: You want to change the seed data when no other data is present in the database: You should simply redo the rake db:seed after updating the seed.rb file. Make sure you have MyModel.delete_all before you try to add anything to that model. 2: You want to change

tensorflow随机张量创建

妖精的绣舞 提交于 2019-11-29 04:33:50
TensorFlow 有几个操作用来创建不同分布的随机张量。注意随机操作是有状态的,并在每次评估时创建新的随机值。 下面是一些相关的函数的介绍: tf.random_normal 从正态分布中输出随机值。 random_normal( shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None ) args: shape:一维整数或 Python 数组表示输出张量的形状。 mean:dtype 类型的0-D张量或 Python 值表示正态分布的均值。 stddev:dtype 类型的0-D张量或 Python 值表示正态分布的标准差。 dtype:输出的类型。 seed:一个 Python 整数。用于为分发创建一个随机种子。 name:操作的名称(可选)。 返回:将返回一个指定形状的张量,通过符合要求的随机值填充。 tf.truncated_normal 生成的值遵循具有指定平均值和标准差的正态分布,和tf.random_normal不同之处在于其平均值大于 2 个标准差的值将被丢弃并重新选择。 tf.truncated_normal( shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None ) args: shape

Better random algorithm?

送分小仙女□ 提交于 2019-11-29 02:31:13
I'm making a game in C++ and it involves filling tiles with random booleans (either yes or no) whether it is yes or no is decided by rand() % 1 . It doesn't feel very random. I'm using srand with ctime at startup, but it seems like the same patterns are coming up. Are there any algorithms that will create very random numbers? Or any suggestions on how I could improve rand() ? True randomness often doesn't seem very random. Do expect to see odd runs. But at least one immediate thing you can do to help is to avoid using just the lowest-order bit. To quote Numerical Recipes in C: If you want to

set random seed programwide in python

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 20:59:37
I have a rather big program, where I use functions from the random module in different files. I would like to be able to set the random seed once, at one place, to make the program always return the same results. Can that even be achieved in python ? The main python module that is run should import random and call random.seed(n) - this is shared between all other imports of random as long as somewhere else doesn't reset the seed. zss 's comment should be highlighted as an actual answer: Another thing for people to be careful of: if you're using numpy.random, then you need to use numpy.random

Seeding file uploads with CarrierWave, Rails 3

落花浮王杯 提交于 2019-11-28 19:50:34
问题 I'm trying to seed a database in Rails 3 with images using CarrierWave, however nothing I try seems to work short of having to upload them all by hand. pi = ProductImage.new(:product => product) pi.image = File.open(File.join(Rails.root, 'test.jpg')) pi.store_image! # tried with and without this product.product_images << pi product.save! Anybody know how to seed using CarrierWave at all? 回答1: Turns out the documentation for CarrierWave is slightly wrong. There is a more up to date piece of

How to seed data with AddOrUpdate with a complex key in EF 4.3

随声附和 提交于 2019-11-28 15:50:54
I am trying to seed a development database with some test data. I have used context.People.AddOrUpdate(p => p.Id, people)); with much success. I have another table that I need to seed, in which I would not know the primary key. For example, I would want to AddOrUpdate based on the First and Last names matching. I am unsure how to write the Expression correctly. context.People.AddOrUpdate(p => p.FirstName && p.LastName, people); is obviously incorrect, but I hope it conveys the solution I am looking for. Try this: context.People.AddOrUpdate(p => new { p.FirstName, p.LastName }, people); If you