non-uniform-distribution

Implementing Box-Mueller random number generator in C#

不羁岁月 提交于 2019-12-18 02:51:49
问题 From this question: Random number generator which gravitates numbers to any given number in range? I did some research since I've come across such a random number generator before. All I remember was the name "Mueller", so I guess I found it, here: Box-Mueller transform I can find numerous implementations of it in other languages, but I can't seem to implement it correctly in C#. This page, for instance, The Box-Muller Method for Generating Gaussian Random Numbers says that the code should

Implementing Box-Mueller random number generator in C#

不羁岁月 提交于 2019-12-18 02:51:38
问题 From this question: Random number generator which gravitates numbers to any given number in range? I did some research since I've come across such a random number generator before. All I remember was the name "Mueller", so I guess I found it, here: Box-Mueller transform I can find numerous implementations of it in other languages, but I can't seem to implement it correctly in C#. This page, for instance, The Box-Muller Method for Generating Gaussian Random Numbers says that the code should

making non-uniform probability distribution in java

核能气质少年 提交于 2019-12-13 08:59:58
问题 i am having total no of elements(say 500) in a java class, which will generate a population of 3 diff type (type A,Type B and Type C) of objects with a probability of A=0.3,B=0.2,C=0.5. i am not able to find a nice and easy solution ,can any one help me with a sample code or some reference Thanks in advance 回答1: For each element, generate a random int r between 0 and 9. If 0 <= r < 3 then Type A. If 3 <= r < 5 then Type B. If 5 <= r < 10 then Type C. 来源: https://stackoverflow.com/questions

Generate an array of random integers with non-uniform distribution

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 10:16:36
问题 I want to write Java code to produce an array of random integers in the range [1,4]. The array's length is N, which is provided at run time. The problem is that the range [1,4] is not uniformly distributed: It means that if I create arrays with N=100, the number '1' will appear averagely 40 times in an array, number '2' 10 times, and so on. For now I am using this code to generate uniform-distributed random numbers in range [1,4]: public static void main(String[] args) { int N; System.out

Effective Java Item 47: Know and use your libraries - Flawed random integer method example

半城伤御伤魂 提交于 2019-11-30 13:14:47
问题 In the example Josh gives of the flawed random method that generates a positive random number with a given upper bound n , I don't understand the two of the flaws he states. The method from the book is: private static final Random rnd = new Random(); //Common but deeply flawed static int random(int n) { return Math.abs(rnd.nextInt()) % n; } He says that if n is a small power of 2, the sequence of random numbers that are generated will repeat itself after a short period of time. Why is this

Effective Java Item 47: Know and use your libraries - Flawed random integer method example

不想你离开。 提交于 2019-11-30 06:37:38
In the example Josh gives of the flawed random method that generates a positive random number with a given upper bound n , I don't understand the two of the flaws he states. The method from the book is: private static final Random rnd = new Random(); //Common but deeply flawed static int random(int n) { return Math.abs(rnd.nextInt()) % n; } He says that if n is a small power of 2, the sequence of random numbers that are generated will repeat itself after a short period of time. Why is this the case? The documentation for Random.nextInt() says Returns the next pseudorandom, uniformly

Implementing Box-Mueller random number generator in C#

≡放荡痞女 提交于 2019-11-28 23:50:12
From this question: Random number generator which gravitates numbers to any given number in range? I did some research since I've come across such a random number generator before. All I remember was the name "Mueller", so I guess I found it, here: Box-Mueller transform I can find numerous implementations of it in other languages, but I can't seem to implement it correctly in C#. This page, for instance, The Box-Muller Method for Generating Gaussian Random Numbers says that the code should look like this (this is not C#): #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time

Java: random integer with non-uniform distribution

♀尐吖头ヾ 提交于 2019-11-28 18:35:37
How can I create a random integer n in Java, between 1 and k with a "linear descending distribution", i.e. 1 is most likely, 2 is less likely, 3 less likely, ..., k least likely, and the probabilities descend linearly, like this: I know that there are dosens of threads on this topic already, and I apologize for making a new one, but I can't seem to be able to create what I need from them. I know that using import java.util.*; , the code Random r=new Random(); int n=r.nextInt(k)+1; creates a random integer between 1 and k , distributed uniformly. GENERALIZATION: Any hints for creating an

Java: random integer with non-uniform distribution

不打扰是莪最后的温柔 提交于 2019-11-27 11:29:52
问题 How can I create a random integer n in Java, between 1 and k with a "linear descending distribution", i.e. 1 is most likely, 2 is less likely, 3 less likely, ..., k least likely, and the probabilities descend linearly, like this: I know that there are dosens of threads on this topic already, and I apologize for making a new one, but I can't seem to be able to create what I need from them. I know that using import java.util.*; , the code Random r=new Random(); int n=r.nextInt(k)+1; creates a