All Questions

Tagged with
Filter by
Sorted by
Tagged with
140 votes
3 answers
10k views

Why does this random value have a 25/75 distribution instead of 50/50?

Edit: So basically what I'm trying to write is a 1 bit hash for double. I want to map a double to true or false with a 50/50 chance. For that I wrote code that picks some random numbers (just as an ...
gvlasov's user avatar
  • 19.3k
76 votes
13 answers
72k views

How to pick an item by its probability?

I have a list of items. Each of these items has its own probability. Can anyone suggest an algorithm to pick an item based on its probability?
Ruzanna's user avatar
  • 9,816
68 votes
11 answers
86k views

Random number with Probabilities

I am wondering what would be the best way (e.g. in Java) to generate random numbers within a particular range where each number has a certain probability to occur or not? e.g. Generate random ...
marc wellman's user avatar
  • 5,846
54 votes
7 answers
306k views

How to calculate mean, median, mode and range from a set of numbers

Are there any functions (as part of a math library) which will calculate mean, median, mode and range from a set of numbers.
user339108's user avatar
  • 12.8k
44 votes
5 answers
88k views

Probability in Java

I was curious to know, how do I implement probability in Java? For example, if the chances of a variable showing is 1/25, then how would I implement that? Or any other probability? Please point me in ...
Jeel Shah's user avatar
  • 3,294
30 votes
8 answers
14k views

Random boolean with weight or bias

I need to generate some random booleans. However I need to be able to specify the probability of returning true. As a results doing: private Random random = new Random(); random.nextBoolean(); will ...
diestl's user avatar
  • 2,040
23 votes
5 answers
47k views

Algorithm to generate Poisson and binomial random numbers?

i've been looking around, but i'm not sure how to do it. i've found this page which, in the last paragraph, says: A simple generator for random numbers taken from a Poisson distribution is obtained ...
user avatar
19 votes
6 answers
12k views

Generating N numbers that sum to 1

Given an array of size n I want to generate random probabilities for each index such that Sigma(a[0]..a[n-1])=1 One possible result might be: 0 1 2 3 4 0.15 0.2 0.18 0.22 0.25 ...
Yuval Adam's user avatar
  • 163k
19 votes
4 answers
14k views

Calculate the number of ways to roll a certain number

I'm a high school Computer Science student, and today I was given a problem to: Program Description: There is a belief among dice players that in throwing three dice a ten is easier to get than ...
scrblnrd3's user avatar
  • 7,328
18 votes
2 answers
2k views

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

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 ...
Derek Mok's user avatar
  • 313
18 votes
3 answers
776 views

How was there no collision among 50,000 random 7-digit hex strings? (The Birthday Problem)

I've encountered some code that generates a number of UUIDs via UUID.randomUUID(), takes the last 7 digits of each (recent versions of UUID are uniformly distributed in terms of entropy), and uses ...
Andrew Cheong's user avatar
14 votes
6 answers
3k views

Implementation of a simple algorithm (to calculate probability)

I've been asked (as part of homework) to design a Java program that does the following: Basically there are 3 cards: Black coloured on both sides Red coloured on both sides Black on one side, red on ...
James's user avatar
  • 143
11 votes
5 answers
25k views

Which java-library computes the cumulative standard normal distribution function?

For a project I have a specification with formulas, I have to implement. In these formulas a cumulative standard normal distribution function exists, that takes a float and outputs a probability. The ...
Mnementh's user avatar
  • 50.9k
10 votes
6 answers
6k views

Java double and working with really small values

I have to store the product of several probabilty values that are really low (for example, 1E-80). Using the primitive java double would result in zero because of the underflow. I don't want the value ...
Rex Roy's user avatar
  • 125
10 votes
1 answer
607 views

Space-efficient probabilistic data structures for number retrieval

Consider we have an algorithm that receives a hypothetically long stream of keys. It then generates a value between 0 and 1 for each key, as we process it, for posterior retrieval. The input set is ...
Amelio Vazquez-Reina's user avatar
8 votes
4 answers
5k views

Discrete Probability Distribution in Java

I have a set of integers each of which has a probability assigned, derived from earlier experiments, e.g.: 0 = 0.5 1 = 0.2 2 = 0.3 Complying with the specifications of a probability distribution, ...
Carsten's user avatar
  • 1,952
8 votes
2 answers
4k views

Algorithm for calculating probabilities of a number being drawn opening a book

I have a book with N<10000 pages, and a number x(in the range 1<=x<=40). I want to calculate the probability that, opening that book at random, the combination of the digits of the opened ...
Makers_F's user avatar
  • 3,053
7 votes
2 answers
9k views

Generating random integers within range with a probability distribution

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 and Inverse Gamma are two distributions that show the ...
jmc's user avatar
  • 620
7 votes
3 answers
10k views

Implement probability distribution function in Java problem

I have a function which is in the form of probability distribution function as below: Although I discover some lib providing function to obtain the result as the above formula would do; but I am ...
Alex Jones's user avatar
6 votes
2 answers
719 views

Time efficient implementation of generating probability tree and then sorting the results

I have some events, where each of them has a probability to happen, and a weight if they do. I want to create all possible combinations of probabilities of events, with the corresponding weights. In ...
Siana's user avatar
  • 63
6 votes
4 answers
7k views

Implementing probability distribution function in Java

I'm trying to implement a probability distribution function in java where it returns the ith entry in the array with probability: Fi = 6i(n-i) / (n3 - n) where n is the array length i.e. for an ...
user528676's user avatar
6 votes
1 answer
404 views

java random string generation and birthday paradox

i need to write a random string generation class which generates 7char strings from a 31-char charset of numbers and some alphabets (10+26-5 , 5 vowels omitted). simple maths gives a set of 31^7 ...
Ashish Thukral's user avatar
5 votes
3 answers
182 views

Under what circumstances that you would want to have a different seed for you random number generator?

I am wondering under what circumstances that you would want to have a different seed for you random number generator. I see code somewhere that people create a Random object every time when needed, ...
peter's user avatar
  • 8,383
5 votes
4 answers
1k views

Estimating a probability given other probabilities from a prior

I have a bunch of data coming in (calls to an automated callcenter) about whether or not a person buys a particular product, 1 for buy, 0 for not buy. I want to use this data to create an estimated ...
sanity's user avatar
  • 35.5k
4 votes
3 answers
5k views

Generate random number between 0 and 1 with (negative)exponential distribution

Heyho, I'm trying to generate a random number between 0.0 and 1.0 with exponential/negative exponential distribution. There is an article, which tells that you have to get the "quantile function". ...
maxammann's user avatar
  • 1,028
4 votes
2 answers
5k views

How to compute the probability of a multi-class prediction using libsvm?

I'm using libsvm and the documentation leads me to believe that there's a way to output the believed probability of an output classification's accuracy. Is this so? And if so, can anyone provide a ...
Cuga's user avatar
  • 17.8k
4 votes
1 answer
624 views

Java- Math.random(): Selecting an element of a 13 by 13 triangular array

Edit: This problem is solved. If you would like to help on another problem, please visit Java Biasing Random Numbers in a Triangular Array. I'm doing a multiplication game, so I pick 2 numbers ...
Justin's user avatar
  • 24.7k
4 votes
6 answers
176 views

Is BigInteger#nextProbablePrime accurate up to, at least, 64-bit numbers?

I'm looking to generate prime numbers using BigInteger#nextProbablePrime. The documentation of this method states the following: The probability that the number returned by this method is composite ...
Jacob G.'s user avatar
  • 29.3k
4 votes
2 answers
2k views

is it safe to use string hashcode as etag

Given a certain input parameter, for a rest api i want to use the hashcode as etag. What is the probability that the json response has changed and the hashcode will be the same? Alternatively is ...
David Michael Gang's user avatar
4 votes
1 answer
727 views

Numerical accuracy with log probability Java implementation

Sometimes when you do calculations with very small probabilities using common data types such as doubles, numerical inaccuracies cascade over multiple calculations and lead to incorrect results. ...
bkoodaa's user avatar
  • 5,102
3 votes
4 answers
930 views

Algorithm for probability over 100%

I am in need of an algorithm (in Java, but the theory should be pretty general) for some sort of probability... thing. I don't even know what to call it, which is why I haven't had any luck Googling. ...
DigitalMan's user avatar
  • 2,510
3 votes
5 answers
12k views

Monty Hall Game

I'm a new programmer currently in the process of learning Java. I've got a game here based on the game Let's make a deal & the monty hall problem (https://www.youtube.com/watch?v=mhlc7peGlGg) and ...
Kamhl's user avatar
  • 39
3 votes
3 answers
920 views

How to generate a set of values that follow certain distribution in c++/java?

For example, I have a p.d.f f(x) = 1/25 - x/1250 (from x = 0 to 50); My question is that how to generate a set of values that satisfy the given p.d.f. Please give an idea about how to implement in c++ ...
user499568's user avatar
3 votes
3 answers
448 views

Why is my simulation not finding infinite expected value?

In the Youtube video Numberphile Infinity (starting at 6:09) there is an experiment described (the St. Petersburg Paradox) in which a game has infinite expected value. I tried to write a Java program ...
Derek Zheng's user avatar
3 votes
1 answer
5k views

Generating a unique ID for every request in a distributed system

I'm trying to generate a unique id for each request in a DS. I'm thinking of concatenating a random integer and timestamp of the request's receipt. Since, getting a random integer can result in ...
user1071840's user avatar
  • 3,552
3 votes
3 answers
1k views

Randomly selecting points in a plane, with a higher probability of selection given to closer points

I've got a problem I'm not too sure how to solve. I have a 2d space with several points in it. I also have a current point, which is one of the points in the space. I want to randomly select one of ...
Graham's user avatar
  • 1,064
3 votes
2 answers
665 views

Rating Articles - Sentiment Analysis [closed]

I am working on a Java program(classifier) which reads a given text file and outputs the related sentiment (Positive or Negative or Neutral). The program calculates three probabilities for the three ...
Ankit Rustagi's user avatar
3 votes
2 answers
2k views

Compute probability over a multivariate normal

My question addresses both mathematical and CS issues, but since I need a performant implementation I am posting it here. Problem: I have an estimated normal bivariate distribution, defined as a ...
unziberla's user avatar
  • 555
3 votes
1 answer
71 views

Java random intersection in a range: unexpected results

Please consider this piece of code: private static final Random RANDOM = new Random(); public static void main(String[] args) { long distinct = IntStream.range(0, 600) ....
silent-box's user avatar
  • 1,658
3 votes
3 answers
4k views

Dice Sum Probability with Different types of Dice

I am currently working on a java application where I need to calculate the probabilities of rolling each sum for a variety of dice. The dice types I am supporting are d4 (4 sided dice), d6 (6 sided ...
Andrew's user avatar
  • 922
3 votes
4 answers
13k views

How do I generate normal cumulative distribution in Java? its inverse cdf? How about lognormal?

I am brand new to Java, second day! I want generate samples with normal distribution. I am using inverse transformation. Basically, I want to find the inverse normal cumulative distribution, then ...
user1061210's user avatar
3 votes
2 answers
533 views

I need an efficient algorithm and/or code for a modelling Poisson distribution of a system

eeesh that title isn't very good. Here is the situation. I have a simulation that runs in real time, I'm trying to efficiently simulate a random count rate that has a known expectation value over a ...
Neilos's user avatar
  • 2,726
3 votes
4 answers
1k views

How to calculate the probability of getting the sum X using N six-sided dice

The Challenge: For example, what is the probability of getting the sum of 15 when using 3 six-sided dice. This can be for example by getting 5-5-5 or 6-6-3 or 3-6-6 or many more options. A brute force ...
riorio's user avatar
  • 6,706
3 votes
2 answers
92 views

Checking if 20 random booleans have the same value

I am trying to generate 20 random booleans and see if they have the same value i.e. either all true or all false. I expected the program to run for a while as the probability should be 1/(2^20) *100 * ...
xcoder's user avatar
  • 1,396
3 votes
1 answer
690 views

How to programmatically calculate a discrete probabilities

I am using EnumeratedIntegerDistribution to generated samples from my set of keys. How to programmatically calculate a 'discrete probabilities' array. for example I might want an approximate 'normal' ...
dmc's user avatar
  • 401
3 votes
2 answers
442 views

Calculating average in a TestLuck (Probability) Program

I'm a student, trying to write a program that tests probability. It's called TestLuck it's supposed to generate a user determined amount of IntArrayLogs(ADT's) that are populated with random values. ...
pasha_codes's user avatar
3 votes
2 answers
463 views

Are there any implementations of Subjective Logic based trust metrics out there? [closed]

Subjective Logic is fundamental as part of my next project, and I was just wondering if there are any implementations already out there. I've read some things (not a lot) about the operators but I'm ...
liamzebedee's user avatar
  • 14.3k
2 votes
3 answers
20k views

Java: How do I simulate probability?

I have a set of over 100 different probabilities ranging from 0.007379 all the way to 0.913855 (These probabilities were collected from an actuary table http://www.ssa.gov/oact/STATS/table4c6.html). ...
Adam Soffer's user avatar
  • 1,644
2 votes
1 answer
4k views

Get risk predictions in WEKA using own Java code

I already checked the "Making predictions" documentation of WEKA and it contains explicit instructions for command line and GUI predictions. I want to know how to get a prediction value like the one ...
user avatar
2 votes
3 answers
12k views

How do you generate a random number with equal probability using Math.random() in Java [duplicate]

I'm currently working through an exercise where I am required to generate a random number which can be one of 4 values. (note I'm only allowed to use Math.random()) 0 1 2 or 3 Currently I am using ...
JWyatt's user avatar
  • 129

1
2 3 4 5