LUA中的随机种子 [英] randomseed in LUA

查看:327
本文介绍了LUA中的随机种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究随机数字的代码.我将math.randomseed(os.time())放入循环中.代码如下:

I am working on a code that randomizes numbers. I put math.randomseed(os.time()) inside a loop. The code goes like this:

for i = 1, 1000 do
  math.randomseed( os.time() )
  j = math.random(i, row-one)
  u[i], u[j] = u[j], u[i]
  for k = 1, 11 do
     file:write(input2[u[i]][k], " ")
  end
  file:write"\n"
end

当我多次运行它时,整个输出始终是相同的.重新运行时,随机种子不是应该防止重复吗?

And when I run it several times, the whole output is always the same. Isn't the randomseed supposed to prevent repeats when re-run?

推荐答案

在程序开始时调用math.randomseed 一次.毫无意义地循环调用它.

Call math.randomseed once at the start of the program. No point calling it in a loop.

这篇关于LUA中的随机种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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