random-number-generator

Create programmatic colour picker

How would one create a deterministic Javascript HTML colour picker which given arguments of how many colours are desired returns an array of HTML hex colour codes, ie: function createColours(numColours) { return [/* colours array of size numColours */] } The colours themselves can be chosen / generated randomly, but the method m...

Ensure uniform (ish) distribution with random number generation

I have a list of objects and I would like to access the objects in a random order continuously. I was wondering if there was a way of ensuring that the random value were not always similar. Example. My list is a list of Queues, and I am trying to interleave the values to produce a real-world scenario for testing. I don't particularly...

Is the Random Generator from Delphi the same calculation as C# if fed the same seed?

I'm translating some Delphi code into c# code when I ran into this. I don't have an environment setup for Delphi so I can't test it myself. Delphi: RandSeed := var1; Result := Random($FF); c#: Random RandSeed = new Random(var1); Result = RandSeed.Next(255); Would these put the same value in Result? If not, any ideas on a way to do...

Compiling with operator() under GCC 3.3 Problem in Boost

Hi, I have the following snippet: #include <boost/random/lognormal_distribution.hpp> #include <boost/random/lagged_fibonacci.hpp> int main() { const double mean = 0.0; const double sigma = 1.0; boost::lognormal_distribution<double> lognorm_dist(mean, sigma); boost::lagged_fibonacci44497 engine; // the following line giv...

Pseudo-random number generator

What is the best way to create the best pseudo-random number generator? (any language works) ...

When using random, which form returns an equal 50% chance?

I'm guessing that most built in random generators return something like this: [0.0, 1.0) so if I would like a 50% chance would I use something like this: if random() < .5 or something like: if random() <= .5 Thanks for the help. ...

Thread-safe uniform random number generator

I have some parallel Fortran90 code in which each thread needs to generate the same sequence of random numbers. I have a random number generator that seems to be thread-unsafe, since, for a given seed, I'm completely unable to repeat the same results each time I run the program. I surfed unsuccessfully (almost) the entire web looking...

Generating Random Number with Certain Rate

Dear all, I have the following C++ code that tried to generate a random number. The idea is we given some rate "x" and number of runs; we hope it would generate the number as many as (x * number of runs times). #include <iostream> #include <vector> #include <fstream> #include <sstream> #include <time.h> using names...

Do PRNG need to be thread safe?

As long as concurrent calls don't cause seg-v's or return the same value, what reasons are there for preventing race conditions and data corruption in PRNGs when those error's primary effects are unpredictable results and that is the point of a PRNG? Edit: are there any PRNG that wouldn't suffer under race conditions and data corrupti...

problem with Random.nextGaussian()

Random.nextGaussian() is supposed to give random no.s with mean 0 and std deviation 1. Many no.s it generated are outside range of [-1,+1]. how can i set so that it gives normally distributed random no.s only in the range -1 to 1. ...

Why is it hard for a program to generate random numbers?

My kids asked me this question and I couldn't really give a concise, understandable explanation. So I'm hoping someone on SO can. ...

Objective C: Modulo bias

Using value = arc4random() % x How can I avoid or eliminate modulo bias? Thanks all. BTW, at least according to Wikipedia, modulo bias is an issue when programming games of chance. ...

Bimodal distribution in C or Python

What's the easiest way to generate random values according to a bimodal distribution in C or Python? I could implement something like the Ziggurat algorithm or a Box-Muller transform, but if there's a ready-to-use library, or a simpler algorithm I don't know about, that'd be better. ...

True (not pseudo) random number generators. What's out there?

I am looking for affordable solutions that generate true random numbers. I have found LavaRnd, which is a cryptographically sound random number generator. Does anybody has experience in this field and/or knows about other solutions? PS: IMHO the SO question True random number generator did not really cover this EDIT: My curiosity i...

Fastest implementation of a true random number generator in C#

I was reading about Random.Next() that for "cryptographically secure random number suitable for creating a random password" MSDN suggests RNGCryptoServiceProvider Class What the speed penality? There is some fastest way to get true random numbers? EDIT: With Random.Next() I get a new random number. And with... byte[] randomNumber = ne...

Generate random values in C#

How can I generate random Int64 and UInt64 values using the Random class in C#? ...

Generate User Friendly Codes

I am researching methods to generate a random human friendly code but not (easily) guessable. This will be used to give away prizes (think unique discount codes). We are to generate about 50k. Are there any standard methods/algorithms to accomplish this? I was thinking of using a GUID and applying CRC. Is this a bad idea? Using .netfram...

Create Random Number Sequence with No Repeats

Duplicate: Unique random numbers in O(1)? I want an pseudo random number generator that can generate numbers with no repeats in a random order. For example: random(10) might return 5, 9, 1, 4, 2, 8, 3, 7, 6, 10 Is there a better way to do it other than making the range of numbers and shuffling them about, or checking the genera...

simulating randomness

I'm just curious... How do you simulate randomness? How is it done in modern OS (Windows, Linux, etc.)? Edit: Okay, NOT JUST GENERATING RANDOM NUMBER, which can be just done with calling rand() functions in most high level programming languages. But, I'm more concerned with how it is actually done in modern operating systems. ...

What is the proper method of constraining a pseduo-random number to a smaller range?

What is the best way to constrain the values of a PRNG to a smaller range? If you use modulus and the old max number is not evenly divisible by the new max number you bias toward the 0 through (old_max - new_max - 1). I assume the best way would be something like this (this is floating point, not integer math) random_num = PRNG() / ma...