使用概率分布生成范围内的随机整数

编程入门 行业动态 更新时间:2024-10-08 20:28:37
本文介绍了使用概率分布生成范围内的随机整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个问题,我想使用概率分布生成1到5之间的一组随机整数值。

I have a problem where I want to generate a set of random integer values between 1 and 5 inclusive using a probability distribution.

Poisson和Inverse Gamma是两个分布,显示了我所发现的特征(多数均值,更低的数字)。

Poisson and Inverse Gamma are two distributions that show the characteristics I am after (majority at mean, less higher numbers) that I have found.

我正在考虑使用 Apache Commons Math 但我我不知道如何使用可用的发行版生成我想要的数字。

I am looking at using Apache Commons Math but I wasn't sure how to generate the numbers I wanted using the distributions available.

推荐答案

从您的问题描述中,它听起来像你实际上想要一个离散概率分布生成的样本,你可以使用 EnumeratedIntegerDistribution 。为每个整数选择合适的概率,可能类似以下内容满足您的需求:

From your problem description, it sounds like you actually want a sample generated from a discrete probability distribution, and you can use EnumeratedIntegerDistribution for this purpose. Choose appropriate probabilities for each of your integers, maybe something like the following would meet your needs:

int[] numsToGenerate = new int[] { 1, 2, 3, 4, 5 }; double[] discreteProbabilities = new double[] { 0.1, 0.25, 0.3, 0.25, 0.1 }; EnumeratedIntegerDistribution distribution = new EnumeratedIntegerDistribution(numsToGenerate, discreteProbabilities); int numSamples = 100; int[] samples = distribution.sample(numSamples);

只需将 discreteProbabilities 值调整为任何你要求。

Just tweak the discreteProbabilities values to whatever you require.

更多推荐

使用概率分布生成范围内的随机整数

本文发布于:2023-10-26 06:48:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   整数   概率

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!