seed

线性同余法的伪随机数

匿名 (未验证) 提交于 2019-12-03 00:03:02
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] 来源:博客园 作者: LittlePage 链接:https://www.cnblogs.com/littlepage/p/11515534.html

随机数是骗人的,.Net、Java、C为我作证(转)

匿名 (未验证) 提交于 2019-12-02 21:52:03
原文链接: http://www.cnblogs.com/CielWater/p/3982076.html 几乎所有编程语言中都提供了"生成一个随机数"的方法,也就是调用这个方法会生成一个数,我们事先也不知道它生成什么数。比如在.Net中编写下面的代码: Random rand = newRandom(); Console.WriteLine(rand.Next()); 运行后结果如下: Next()方法用来返回一个随机数。同样的代码你执行和我的结果很可能不一样,而且我多次运行的结果也很可能不一样,这就是随机数。 一、陷阱 看似很简单的东西,使用的时候有陷阱。我编写下面的代码想生成100个随机数: for(int i=0;i<100;i++) { Random rand = new Random(); Console.WriteLine(rand.Next()); } 太奇怪了,竟然生成的"随机数"有好多连续一样的,这算什么"随机数"呀。有人指点"把new Random()"放到for循环外面就可以了: Random rand = newRandom(); for(int i=0;i<100;i++) { Console.WriteLine(rand.Next()); } 运行结果: 确实可以了! 二、这是为什么呢? 这要从计算机中"随机数"产生的原理说起了。我们知道

Seed multiple rows at once laravel 5

淺唱寂寞╮ 提交于 2019-12-02 21:45:24
I'm currently trying to seed my users table. If I try it like this with 2 rows, it fails. It works fine if I just use a single array instead of the 2 arrays inside the $users array to create some fake data. What am I doing wrong, what is the proper way to do this? class UserTableSeeder extends Seeder { public function run() { DB::table('users')->delete(); $users = [ ['id' => 1, 'name' => 'Stephan de Vries', 'username' => 'stephan', 'email' => 'stephan-v@gmail.com', 'password' => bcrypt('carrotz124')], ['id' => 2, 'name' => 'John doe', 'username' => 'johnny', 'email' => 'johndoe@gmail.com',

How to start writing Gnome Shell extensions

社会主义新天地 提交于 2019-12-02 17:06:58
I have found it's very hard to find documentation about Gnome Shell Extensions. I found some bits on Gnome Wiki (and it's first-level links), but it's not much: http://live.gnome.org/GnomeShell/Extensions The problem here is GJS and it's bindings. Absolutely no documentation, got lot's of SIGSEGVs, binding is just not ready (GLib, Gio and others). The only working one is unofficial documentation generated from GIR for Seed JavaScript implementation: http://roojs.org/seed/gir-1.2-gtk-2.0/seed/ Where to get more examples? I want read directories, files, spawn processes, open network sockets and

XCTF dice_game write up

夙愿已清 提交于 2019-12-02 03:05:28
nc一下给的地址和端口号,大概这个样子。 IDA Pro 看一下源文件 看一下sub_A20()函数,就是比较了你输入的数与随机数是否相同 如果五十次都相同,就输出flag。 我们要做的就是,将seed覆盖掉,并且去预测生成的随机数。 这边就可以看到,buf覆盖0x40位就能覆盖到seed。 exp: from pwn import * from ctypes import * p=remote('111.198.29.45','53746') libc = cdll.LoadLibrary("libc.so.6") p.recv() payload=0x40*"a"+p64(0) p.sendline(payload) a=[] for i in range(50): a.append(libc.rand()%6+1) print(a) for i in a: p.recv() print(p.recv()) p.sendline(str(i)) p.interactive() 喜提flag! 来源: https://www.cnblogs.com/mzstar/p/11727904.html

Issues with seeding a pseudo-random number generator more than once?

江枫思渺然 提交于 2019-12-01 18:12:52
I've seen quite a few recommendations for not seeding pseudo-random number generators more than once per execution, but never accompanied by a thorough explanation. Of course, it is easy to see why the following (C/C++) example is not a good idea: int get_rand() { srand(time(NULL)); return rand(); } since calling get_rand several times per second produces repeated results. But wouldn't the following example still be an acceptable solution? MyRand.h #ifndef MY_RAND_H #define MY_RAND_H class MyRand { public: MyRand(); int get_rand() const; private: static unsigned int seed_base; }; #endif MyRand

Issues with seeding a pseudo-random number generator more than once?

一曲冷凌霜 提交于 2019-12-01 17:54:23
问题 I've seen quite a few recommendations for not seeding pseudo-random number generators more than once per execution, but never accompanied by a thorough explanation. Of course, it is easy to see why the following (C/C++) example is not a good idea: int get_rand() { srand(time(NULL)); return rand(); } since calling get_rand several times per second produces repeated results. But wouldn't the following example still be an acceptable solution? MyRand.h #ifndef MY_RAND_H #define MY_RAND_H class

how to get reproducible result in Tensorflow

℡╲_俬逩灬. 提交于 2019-12-01 08:00:58
I built 5-layer neural network by using tensorflow. I have a problem to get reproducible results (or stable results). I found similar questions regarding reproducibility of tensorflow and the corresponding answers, such as How to get stable results with TensorFlow, setting random seed But the problem is not solved yet. I also set random seed like the following tf.set_random_seed(1) Furthermore, I added seed options to every random function such as b1 = tf.Variable(tf.random_normal([nHidden1], seed=1234)) I confirmed that the first epoch shows the identical results, but not identical from the

how to get reproducible result in Tensorflow

ε祈祈猫儿з 提交于 2019-12-01 06:01:30
问题 I built 5-layer neural network by using tensorflow. I have a problem to get reproducible results (or stable results). I found similar questions regarding reproducibility of tensorflow and the corresponding answers, such as How to get stable results with TensorFlow, setting random seed But the problem is not solved yet. I also set random seed like the following tf.set_random_seed(1) Furthermore, I added seed options to every random function such as b1 = tf.Variable(tf.random_normal([nHidden1],

boost::random generate the same number every time

放肆的年华 提交于 2019-12-01 03:20:06
main .cpp #include "stdafx.h" #include "random_generator.h" int main ( int argc, char *argv[] ) { cout.setf(ios::fixed); base_generator_type base_generator; int max = pow(10, 2); distribution_type dist(1, max); boost::variate_generator<base_generator_type&, distribution_type > uni(base_generator, dist); for ( int i=0; i<10; i++ ) { //cout << random_number(2) << endl; cout << uni() << endl; } return EXIT_SUCCESS; } /* ---------- end of function main ---------- */ random_gemerator.h #include "stdafx.h" #include <boost/random.hpp> #include <boost/generator_iterator.hpp> typedef boost::mt19937