random-number-generator

Generating a random seed in PHP for consumption by Flash

I'm working on a project with remote Flash developers, and they have requested that when my PHP application sets up the HTML to load their Flash object, I pass in a seed that they can use to generate random numbers with (the seed is stored so that a particular game can be replayed later). If you were seeding PHP's RNG, you might use the...

A Good and SIMPLE Measure of Randomness

What is the best algorithm to take a long sequence of integers (say 100,000 of them) and return a measurement of how random the sequence is? The function should return a single result, say 0 if the sequence is not all all random, up to, say 1 if perfectly random. It can give something in-between if the sequence is somewhat random, e.g. ...

In PHP, how do I generate a big pseudo-random number?

I'm looking for a way to generate a big random number with PHP, something like: mt_rand($lower, $upper); The closer I've seen is gmp_random() however it doesn't allow me to specify the lower and upper boundaries only the number of bits per limb (which I've no idea what it is). EDIT: Axsuuls answer seems to be pretty close to what I w...

How to generate a RNGCryptoServiceProvider-like number in TSQL

Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL without having to register any .NET Assemblies? ...

Weighted Random Number Generation in C#

Question How can I randomly generate one of two states, with the probability of 'red' being generated 10% of the time, and 'green' being generated 90% of the time? Background Every 2 second either a green or a red light will blink. This sequence will continue for 5 minutes. The total number of occurrences of a blinking light should...

TSQL Generate 5 character length string, all digits [0-9] that doesn't already exist in database...

What's the best way to do this? I need to generate a 5 digit length string where all the characters are numeric. However, I need to be able to do this 'x' amount of times (user variable) and store this random strings in a database. Furthermore, I can't generate the same string twice. Old strings will be removed after 6 months. Pseud...

Non-Uniform Random Number Generator Implementation?

I need a random number generator that picks numbers over a specified range with a programmable mean. For example, I need to pick numbers between 2 and 14 and I need the average of the random numbers to be 5. I use random number generators a lot. Usually I just need a uniform distribution. I don't even know what to call this type of di...

Crappy Random Number Generator

This may sound like an odd question, but where can I find a random number generator that works in C or C++ that is not very good? Context: I'm creating some tree graph plotting software and testing it by using multi-digit random numbers (so each digit becomes a node in the tree). The random number generator I've been using - which is th...

Obscure VBMath random numbers generator behavior.

Hi, I want to repeat a random number sequence generated by a legacy software using the VBMath.Rnd and VBMath.Randomize functions in VB .NET Reading on the documentation for those functions on MSDN i found that you are supposed to "reset" the generator calling Rnd with a negative value if you want the same seed to give you the same res...

How do you generate cryptographically secure random numbers with PHP?

We need to generate a cryptographically random string to use as an authentication token, which will be tied to session data in the database. We are using PHP, which doesn't appear to have a suitable random number generator built-in. How can we generate a cryptographically secure random string of N length using php? Also note, due to t...

How different do random seeds need to be?

Consider code like this (Python): import random for i in [1, 2, 3, 4]: random.seed(i) randNumbers = [random.rand() for i in range(100)] # initialize a list with 100 random numbers doStuff(randNumbers) I want to make sure that randNumbers differ significantly from one call to another. Do I need to make sure the seed number...

Generating random number between [-1, 1] in C?

I have seen many questions on SO about this particular subject but none of them has any answer for me, so I thought of asking this question. I wanted to generate a random number between [-1, 1]. How I can do this? ...

How to generate random numbers in microcontrollers efficiently?

Any general guidelines? Or particular fast method? Thanks in advance. ...

Why would rand() return a negative value when min and max values are positive?

Hi, I have a simple piece of PHP code which requires a random number to be created. However, even though the input is always positive, it sometimes returns a negative output. Here's my debug code: $debt = rand($this->gdp * 0.02, $this->gdp * 0.17); echo "<p>GDP: ".$this->gdp." rand(".$this->gdp * 0.02." , ".$this->gdp * 0.17.") = <st...

Properly Seeding Random numbers in Class Library called from ASP.Net Web Page

I'm experiencing a problem with my random number generator in a class library returning the same value repeatedly. It returns the same value b/c it is repeatedly initialized with the default constructor - for example: public static T GetRandomValue<T>(T[] array) { int ndx = new Random().Next(array.Length); return a...

Dice Roller using Tkinter

Thank you to everybody who helped answer my last question: My friend took the code, and has attempted to use Tkinter to make a box that we could use to make things nicer-looking, but he has been unable to integrate the dice roller from the last question and the Tkinter. Any help or ideas in getting the dice roller into the code below w...

C# Random Number

I am working on a project in which I need to generate 8 random numbers. I am having an issue with the random number part being very time consuming for some reason. What I mean by 8 random numbers is I need a string that is 8 characters long consisting of the numbers 0-9. Example 01234567 or 23716253 etc. I tried looping 8 times generat...

Randoms numbers on iPhone

Hi, What is better? I have the prioritized in the order of "goodness", am I correct? arc4random randmom rand 1 - best, 3 - worst I need a really good randmon number gen for a lowe number (< 50), so I using % 50 to obtain numbers below 50. Thanks ...

C# Normal Random Number

I would like to create a function that accepts Double mean, Double deviation and returns a random number with a normal distribution. Example: if I pass in 5.00 as the mean and 2.00 as the deviation, 68% of the time I will get a number between 3.00 and 7.00 My statistics is a little weak…. Anyone have an idea how I should approach thi...

boost random number library, use same random number generator for different variate generators

It seems that one can use the following code to produce random numbers from a particular Normal distribution: float mean = 0, variance = 1; boost::mt19937 randgen(static_cast<unsigned int>(std::time(0))); boost::normal_distribution<float> noise(mean, variance); variate_generator<mt19937, normal_distribution<float> > nD(randgen, noise); ...