需要一个快速的Java beta分发随机数生成器 [英] Need a fast Java beta distribution random number generator

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

问题描述

我需要在某些速度关键代码中生成具有beta分布的随机数。目前我正在使用numerics4j库中的BetaRandomVariable()类 - 但目前占我代码CPU使用率的95%左右!

I need to generate random numbers that have a beta distribution in some speed critical code. Currently I'm using the BetaRandomVariable() class from the numerics4j library - but currently represents about 95% of my code's CPU usage!

任何人都可以推荐更快的生成方式这些随机数?

Can anyone recommend a faster way to generate these random numbers?

推荐答案

你可以看一下 NumPy随机数生成器。它们在C中,但代码相对可读并且允许许可,因此可以轻松地移植到Java。您不需要移植基本的Mersenne Twister生成器,因为Java在其标准库中有一个,只有采用数字的代码形成Mersenne Twister并将其转换为beta分布。我已将大部分NumPy随机数生成器移植到D并发现它们非常高效,您可能会在Java中找到相同的内容。

You can look at the NumPy random number generators. They're in C, but the code is relatively readable and permissively licensed, so they can easily be ported to Java. You don't need to port the basic Mersenne Twister generator as Java has one in its standard library, only the code that takes numbers form the Mersenne Twister and converts it to a beta distribution. I've ported most of the NumPy random number generators to D and found them to be very efficient, and you'll probably find the same in Java.

这篇关于需要一个快速的Java beta分发随机数生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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