random-number-generator

Generating Full Period/Full Cycle Random Numbers or Permutations Similar to LCG but without odd/even

I wish to generate psuedo-random numbers/permutations that 'occupy' a full period or full cycle within a range. Usually an 'Linear Congruential Generator' (LCG) can be used to generate such sequences, using a formula such as: X = (a*Xs+c) Mod R Where Xs is the seed, X is the result, a and c are relatively prime constants and R is the ...

Distributed sequential random number generation in Ruby 1.9.2

The Random class in Ruby 1.9.2 is guaranteed to generate random numbers in the same order, given a particular seed and range. For instance: r = Random.new(23) r.rand(100) # 83 r.rand(100) # 40 But suppose I want to generate the next number in the sequence on another computer (without re-generating the earlier numbers i...

How to make rand() more likely to select certain numbers?

Is it possible to use rand() or any other pseudo-random generator to pick out random numbers, but have it be more likely that it will pick certain numbers that the user feeds it? In other words, is there a way, with rand() or something else, to pick a pseudo random number, but be able to adjust the odds of getting certain outcomes, and h...

What shuffling algorithms exist besides Fisher-Yates and finding the "next permutation?"

Specifically in the domain of one-dimensional sets of items of the same type, such as a vector of integers. Say, for example, you had a vector of size 32,768 containing the sorted integers 0 through 32,767. What I mean by "next permutation" is performing the next permutation in a lexical ordering system. Wikipedia lists two (http://en...

Printing a random number returns a negative number. (/dev/urandom)

I have written a source code to print random numbers within a specified limit.But it is also returning some negative numbers,is this normal?If not how do I rectify it? #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> int main( int argc, char* argv[]) { int fd, n; fd = open("/dev/urandom", ...

Big random numbers in PHP - Is this a good approach?

I need a big(like, say, 128-bit big) random number generator in PHP. I was thinking in storing this number in a string as hexadecimal. Note that this is meant for a login system that mentioned the need for a "random" number, so I'm guessing I really need it to be "random-enough"(because I know pseudo-random is never truly random). The ...

Random generation number doubt

Hi Is there is any way to avoid duplication in random number generation . I want to create a random number for a special purpose. But it's should be a unique value. I don't know how to avoid duplicate random number ie, First i got the random number like 1892990070. i have created a folder named that random number(1892990070). My p...

Does Ruby Have a Random Number Generator Class?

Possible Duplicate: How to get a random number in Ruby? I am just curios but does Ruby have a class for specifically generating random numbers like Java's java.util.Random class, or is the rand method all Ruby has? ...

Ensuring the right kind of operations on the right types

I want to write a program to load a key-value store with lots of random data of random types. Assuming the key-value store supports three types ( strings, lists and sets ) there are operations that are valid for a set (say, union) that are not valid for strings. #define SUBSTR 0 // substring, only on strings #define SEARCH 1 // search...

Random number generator returning zeros

I have an ASP.NET application that relies on the Random class to generate a pseudo-random string. It uses the following code (this is part of a larger piece of sample code provided by Google for apps SSO): public static class SamlUtility { private static Random random = new Random(); private static char[] charMapping = { ...

Random numbers and thread local storage

The accepted answer to this question, and a similar discussion at work today got me to wondering about something. The question was about how to safely generate random numbers in a multi-threaded program. The accepted answer advocates using thread local storage, effectively creating one random number generator per thread. I wonder if t...

CRYPT_GEN_RANDOM strange effects

I want to randomly choose a value from a small range of integers (less than 200). As an alternative to SELECT RAND() I'm trying to use CAST(CAST(CRYPT_GEN_RANDOM(2) AS INTEGER) AS FLOAT) / 65535 but I'm getting some strange effects. For example: WITH Numbers (num) AS ( SELECT num FROM ( VAL...

C# random number generator

I'm looking for a random number that always generates the same "random" number for a given seed. The seed is defined by x + (y << 16), where x and y are positions on a heightmap. I could create a new instance of System.Random every time with my seed, but thats a lot of GC pressure. Especially since this will be called a lot of times. E...

Trouble with C# Random class

Hey guys, I've got a class that represents a coin, which can be flipped with the Coin.Flip() method. Flip() uses random.Next(2); to get either a 0 or a 1 representing heads or tails. This works good.. sort of. For the program, I need to have 2 coins, which I make, lets say coin1 and coin2. coin2 always needs to be flipped straight aft...

Random number generator without dupes in Javascript?

I need help with writing some code that will create a random number from an array of 12 numbers and print it 9 times without dupes. This has been tough for me to accomplish. Any ideas? ...

Is RNGCryptoServiceProvider as good as a hardware RNG?

I'm attempting to work out whether a hardware RNG is actually any safer than RNGCryptoServiceProvider. Given that randomness from RNGCryptoServiceProvider is provided using various system and user data such as the process ID, thread ID, system clock, system time, system counter, memory status, free disk clusters, and hashed user environ...

Evenly distributed hash function

I need a hash function that takes a few (eg. 2 or 3) unsigned integers as input, and returns a floating point value between -1 and +1. The collection of these returned values must be evenly distributed. A sequence of outputs from the function must appear to be a random sequence, even if the input numbers are sequential. Also the faster ...

Can I generate a 6-Digit random number based on two numbers?

I have two numbers: IMEI Number : 12345678912345 Random Pin : 654321 My Random pin changes always. Based on this combination (IMEI and PIN ) is there any way to generate a 6 digit random number? I want to do it in C#. ...

Is using rand() in an INSERT statement also slow?

The MYSQL rand() function is notoriously slow in select statements, is this true for insert statements as well? I would like to insert a new row with random number in the following way: insert into new_table (field1, field2, randomField) values ('Hello', 'Ola', rand()); Will the rand() function become slow as the table gets larger a...

why is RAND_MAX a macro in C++?

Why is it not a const? I think this is not a clear C++ way. Perhaps there is a more C++ way to generate random numbers, is there? ...