JavaScript中的Seedable随机数生成器 [英] Seedable Random number generator in JavaScript

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

问题描述

我正在寻找JavaScript中的随机数生成器,我可以使用某个种子初始化并给出确定性结果(根据该种子)。它应该能够在一定范围内提供随机整数,但是我也可以使用随机数生成器来吐出双精度数(就像Math.random())。

I'm looking for a random number generator in JavaScript which I can initialize with a certain seed and gives a deterministic result (according to that seed). It should be capable of providing random integers within a certain range, however I can work with a random number generator that spits doubles, too (just like Math.random()).

基本上我正在寻找java.util.Random的等价物,如Java World for JavaScript中所知。

Basically I'm looking for an equivalent to java.util.Random as known in the Java World for JavaScript.

这样的内容是否已经嵌入到JavaScript中?是否有一些(可能是HTML5相关的API)指定了这样的东西?有没有提供这样一个随机数生成器的库?

Is there something like this already built into JavaScript? Is there some (maybe HTML5 related API) which specifies such a thing? Is there a library providing such a random number generator?

我在JavaScript中实现了一个遗传算法,我需要能够为相同的输入获得相同的结果(包括种子)用于研究。

I'm implementing a genetic algorithm in JavaScript and I need to be able to harvest the same results for the same inputs (including seed) for research.

推荐答案

这可能会对你有所帮助,我只是在互联网上找到它。它显然是的替代品。Math.random()

This might help you, I just found it on the internet. It's apparently a replacement for Math.random()

http://davidbau.com/encode/seedrandom.js

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

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