为什么我的随机数总是一样的? [英] Why are my random numbers always the same?

查看:24
本文介绍了为什么我的随机数总是一样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Fortran 中的 random_number 子例程,但在不同的程序运行中,生成的数字不会改变.我应该在代码中包含什么,以便每次编译和运行程序时数字都会改变?

I'm using the random_number subroutine from Fortran, but in different runs of program the number which is being produced doesn't change. What should I include in my code so every time I compile and run the program the numbers change?

推荐答案

随机数生成器产生伪随机数.要在每次运行中获得不同的数字,您需要在开始你的程序.这会在伪随机流中选择一个不同的起始位置.

The random number generator produces pseudo-random numbers. To get different numbers each run, you need to initialise the random seed at the start of your program. This picks a different starting position in the pseudo-random stream.

这篇关于为什么我的随机数总是一样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆