All Questions
Tagged with probability c#
84
questions
45
votes
7
answers
74k
views
Generate Random Boolean Probability
I only know how I can generate a random boolean value (true/false).
The default probability is 50:50
But how can I generate a true false value with my own probability?
Let's say it returns true with ...
30
votes
8
answers
26k
views
Distributed probability random number generator
I want to generate a number based on a distributed probability. For example, just say there are the following occurrences of each numbers:
Number| Count
1 | 150
2 | ...
26
votes
8
answers
14k
views
Game Design/theory, Loot Drop Chance/Spawn Rate
I have a very specific and long-winded question for you all. This question is both about programming and game-theory. I recently added spawnable ore to my Turn Based Strategy Game: http://imgur.com/...
23
votes
4
answers
24k
views
Probability Random Number Generator
Let's say I'm writing a simple luck game - each player presses Enter and the game assigns him a random number between 1-6. Just like a cube. At the end of the game, the player with the highest number ...
17
votes
8
answers
12k
views
Creating your own Tinyurl style uid
I'm writing a small article on humanly readable alternatives to Guids/UIDs, for example those used on TinyURL for the url hashes (which are often printed in magazines, so need to be short).
The ...
16
votes
3
answers
25k
views
Percentage Based Probability
I have this code snippet:
Random rand = new Random();
int chance = rand.Next(1, 101);
if (chance <= 25) // probability of 25%
{
Console.WriteLine("You win");
}
else
{
Console.WriteLine("...
13
votes
3
answers
22k
views
c# probability and random numbers
I want to trigger an event with a probability of 25% based on a random number generated between 1 and 100 using:
int rand = random.Next(1,100);
Will the following achieve this?
if (rand<=25)
{
...
11
votes
6
answers
3k
views
Adjust items chance to be selected from a list
I have a list of items. When I create the list each item has equal chance to be selected. But as an item is selected its chance goes down while the others chance goes up. If a new item is added ...
11
votes
2
answers
5k
views
Uniform distribution from a fractal Perlin noise function in C#
My Perlin noise function (which adds up 6 octaves of 3D simplex at 0.75 persistence) generates a 2D array array of doubles.
These numbers each come out normalized to [-1, 1], with mean at 0. I clamp ...
9
votes
3
answers
4k
views
How do I add and subtract probability disributions like real numbers?
I'd like your advice: could you recommend a library that allows you to add/subtract/multiply/divide PDFs (Probability Density Functions) like real numbers?
Behind the scenes, it would have to do a ...
7
votes
4
answers
16k
views
How to create a probability by a given percentage?
I'm trying to create a percentage-based probability for a game. E.g. if an item has a 45% chance of a critical hit, that must mean it is 45 of 100 hits would be critical.
First, I tried to use a ...
7
votes
3
answers
2k
views
Monty Hall Program Simulation (C#)
I am trying to simulate the Monty Hall Problem (because I read from the book Think Statistics that a guy in particular was convinced only after seeing a computer simulation) in C#, the programming ...
7
votes
4
answers
4k
views
Select x random elements from a weighted list in C# (without replacement)
Update: my problem has been solved, I updated the code source in my question to match with Jason's answer. Note that rikitikitik answer is solving the issue of picking cards from a sample with ...
6
votes
3
answers
10k
views
Pick random element from list with probability
I Have a list that contains four item (A, B, C, D). Every item has a probability to be chosen. Let's say for example A has 74% of chance to be picked, B 15%, C 7% ,and D 4%.
I want to create a ...
6
votes
5
answers
3k
views
C# game of chance
I am new to C#.
What I am trying to do
I am trying to create a game of chance system here.
Basically this is how it is:
My question: How do I do to accomplish what I am trying to do?
6
votes
3
answers
3k
views
triggering an event with a certain probability with C#
I'm trying to simulate a realistic key press event. For that reason I'm using SendInput() method, but for greater result I need to specify the delay between keyDOWN and KeyUP events! These numbers ...
5
votes
3
answers
1k
views
How to determine how many times will a statement inside a loop will be executed with conditional statements
There is a test that consists of 12 questions. each question must have a value greater than 4 points. all the question must add to 100. also all the questions must have an integer value.
so a ...
5
votes
4
answers
992
views
Random numbers probability
I am trying to randomly choose from e.g. 4 numbers. I need to compare the probability of these 2 algorithms.
1#
int a = random.Next(0, 4);
if (a = 0)
...
5
votes
1
answer
3k
views
How to make a choice based on a percentage probability
I wish to use the answer provided in this post to randomly choose unique items from a list.
Following the method described, in each iteration of my loop I generate a probability value which is the ...
4
votes
2
answers
3k
views
Weighted random selection using Walker's Alias Method
I was looking for this algorithm
(algorithm which will randomly select from a list of elements where each element has different probability of being picked (weight) )
and found only python and c ...
4
votes
1
answer
241
views
Select items based on popularity: Avoiding a glorified sort
I have a site where users can post and vote on suggestions. On the from page I initially list 10 suggestions and the header fetches a new random suggestion every 7 seconds.
I want the votes to ...
3
votes
4
answers
4k
views
Selecting Random Item from List given probability of each item
Sorry about badly phrased title....
I have an object called NGram
class NGram
{
//other properties
double Probability {get; set;} //Value between 1 and 0
}
Now suppose I have a list of ...
3
votes
5
answers
270
views
Random occurrences
I am not quite sure how to go about this.
I need to generate 14,296 random numbers with different levels of probability.
so for example I need an array containing the numbers 18, 1, and 17. Each ...
3
votes
4
answers
1k
views
Random Probability Selection
Say I have 10 prizes to give to 100 people. Each person gets a shot, one at a time. So if the first person fails to win a prize, the probability goes up, 10 in 99, and so one... Also all 10 prizes ...
3
votes
2
answers
2k
views
How do I transform an Inverse CDF coded for a standard deviation of one to a different STDDEV?
I am doing rejection sampling as part of an algorithm for numerical integration using an inverse cumulative distribution function (CDF).
I found two possible implementations:
In C and Java (and ...
2
votes
6
answers
446
views
Two-value dictionary which returns any of the value for a specific key
I need to create a dictionary that has 2 values per key, and it must return one of the 2 values with the same probability.
Example:
myDicry
{
key = "A", value1=15, value2=56;
}
int firstCall = ...
2
votes
4
answers
2k
views
Quick way of selecting a random item from a list - with varying probabilities based on item value?
(This may not be possible short of writing a decently sized helper method, but regardless, I'd like to figure it out)
Say I have a list:
{1,3,6}
I'd like to get a random item from that list, BUT, I'...
2
votes
3
answers
914
views
Probability of picking a particular number from array
I'm scratching my head for 2 days and can't figure out what's wrong with my code. Lets say that I have 2 arrays:
Array1[33]: 0..31 (it has 2 fives)
Array2[32]: 0..31 (it has one five)
Now I want to ...
2
votes
4
answers
1k
views
How to get a random integer in given boundaries equal to a given number with a given chance?
I need a function like
int f(int min, int max, int x, int chance)
// where accepted chance values are 0 to 100 and x values are min to max
to return a random integer equal or greater than min, ...
2
votes
3
answers
241
views
Do all the numbers have equal probability to be returned on every Random.Next() call?
Is the probability of Random.Next() to return x the next time it's called lower than its probability of returning y if it has just returned x?
2
votes
2
answers
4k
views
multivariate normal distribution given mean vector and covariance matrix
I admit I am being lazy here but is anyone aware of a free math .net library which gives me the output of a normal distribution given a mean vector and a covariance matrix? Thanks.
2
votes
2
answers
357
views
Randomly picking a number from a range of values based on probability
Suppose I have a range of values from 1 to 10. I want to randomly pick a number from this range based on some kind of gaussian probability. So, there is a higher chance to get the values at about 4,5,...
2
votes
2
answers
1k
views
How to get random number with each number has its own probability [duplicate]
For example, I want to get random number from set S = {0, 1, 2, 3}. But instead of each number has same probability to shown (which is 25%), now I have different probability for each number, let say {...
2
votes
2
answers
745
views
Sorting List randomly by weights
The idea is that i have a list of items with each item having a weight attached. Now i want to randomize the order of the list, but i also want to take the weight into account to "bias" the ...
2
votes
1
answer
321
views
Simplification of LootTable probability distribution
I have created a simple LootTable class for a hobby game that I am working on, and it works perfectly fine. However, I am widely aware of a flaw that is present within the code. When I say flaw, I ...
2
votes
1
answer
2k
views
Use rand5(), to generate rand7() (with the same probability) [duplicate]
Possible Duplicate:
Expand a random range from 1–5 to 1–7
I have seen the question in here: Link
The solution the author provided didn't seem to generate the same probability.
For example, the ...
2
votes
1
answer
2k
views
Calculation of probabilities in Naive Bayes in C#
I'm working on a Naive Bayes solution for C# where there are two possible outcomes. I have found a small sample code but was wondering if anyone would be able to explain the last line.
The analyzer ...
1
vote
5
answers
3k
views
.NET's GUID structure
http://msdn.microsoft.com/en-us/library/system.guid.aspx
How does it work? How does it guarantee unique ID? Does it only rely on probability or is there another trick? Can I always trust it to give ...
1
vote
3
answers
730
views
Maths Probability [closed]
What is the probability of getting a 10 or a 11 when a pair of dice are rolled?
How to do
1
vote
2
answers
249
views
Output of code using System.Random does not approach theoretical limit as iterations increase
I'm not good at stats, so I tried to solve a simple problem in C#. The problem: "A given team has a 65% chance to win a single game against another team. What is the probability that they will win a ...
1
vote
3
answers
1k
views
How to detect "Hand" in a card drawing game [closed]
Having an array which represents a 5 picked card out of a full deck (52 cards).
So a random hand will look like this ['H3','H6','D3','D4','S4'], (here is h 2 pairs 4 and 3).
I'm looking for a way to ...
1
vote
2
answers
128
views
use percentage with c# [closed]
I would like to run 3 scenarios. The first has 80% which returns IsRandom = false the other two have 10% each for Group "A" or Group "B".
Here is my code:
Random randomGen = new ...
1
vote
1
answer
3k
views
How to make probability increase over time with predictable outcome
I have a game program that is played by a robot. For simplicity's sake, the game has 2 buttons - "win" and "try again". To win, the robot must simply push the "win" button.
The game involves a ...
1
vote
2
answers
4k
views
Open source statistics library for C# for generating random number of various distributions?
This is for simulation. In particular, I'm trying to generate natural sounding words and names, and the uniform distribution in the Random class provides doesn't cut it.
This isn't a dupe question ...
1
vote
1
answer
3k
views
How To Make A Simple Dice System
First, I want to express that I am writing this with the intentions of following the guidelines of the website itself, which states that anyone may document their work to help facilitate the ...
1
vote
3
answers
1k
views
Random Rotation on a 3D sphere given an angle
This question is in between computer graphic, probability, and programming, but since I am coding it for an Unity project in C# I decided to post it here. Sorry if not appropriate.
I need to solve ...
1
vote
1
answer
764
views
Chances for a collision when using Path.GetRandomFileName
Path.GetRandomFileName returns a crypto-strong string of 11 random chars. It is built of 8 chars + dot + 3 chars, like: "b253i5vu.psf". A char can be a lowercase letter or a number between 0 and 5. So ...
1
vote
1
answer
1k
views
C# and "Weighted probability" [duplicate]
I am looking to pick 1 person from a list of people where each item in the list has a certain "weighting" to it. Let's assume the Person class has the necessary constructor.
public class Person {
...
1
vote
1
answer
53
views
Generate an aleatoire combination of decimal making sure not generate a duplicate of this combination
I wrote the following method to help me to generate a combination of decimal digits in C# :
public static string GenerateCodeNumeric(int length)
{
Random random = new Random();
string ...
1
vote
1
answer
820
views
Winning lottery odds
I have another question about lottery. I have to make this problem: "You want to participate in the game of chance 6 out of 49 with only one variant and you want to know what chances you will win:...