random-number-generator

Can I Do This In Smalltalk?

A class I am taking currently requires us to do all of our coding in smalltalk (it's a Design class). On one of our projects, I am looking to do some things, and am having a tough time finding how to do them. It seems that what most people do is modify their own version of smalltalk to do what they need it to do. I am not at liberty to d...

Generate Random numbers uniformly over entire range

I need to generate random numbers with in specified interval [max,min] Also the random numbers should be uniformly distributed over interval, not located to particular point Currenly I am generating as: for(int i=0;i<6;i++) { DWORD random= rand()%(max-min+1) + min; } From my tests random numbers are generated around one point only ...

System.Random keeps on returning the same value

I am using a System.Random object which is instantiated with a fixed seed all thoughout the application. I am calling the NextDouble method and after some time passed I am getting 0.0 as result. Is there any remedy to this, has anyone else encountered this ? EDIT: I have one seed for the whole run which is set to 1000 for convience sak...

Alternative Entropy Sources

Okay, I guess this is entirely subjective and whatnot, but I was thinking about entropy sources for random number generators. It goes that most generators are seeded with the current time, correct? Well, I was curious as to what other sources could be used to generate perfectly valid, random (The loose definition) numbers. Would using m...

Random Number Generator: Class level or Method level?

Hi! When using a Random Number Generator, which is the better way to use it for greater randomness of the new value: Have a method that instantiates a new instance of the RNG each time and then returns a value? Have an instance of the RNG at the class level, which is instantiated once in the Constructor, and all subsequent calls for a...

C: the definitive truth about rand, random and arc4random

There's a lot of conflicting information about this topic. So let's try to agree on a definitive answer: Which one of these random number generator in C create better randomness: rand, random or arc4random? note: Just to make the question clear, this is not a question about true randomness, it's only a clash between those 3. As poin...

Seeding a random number generator in .Net

I have a PRNG with nice properties which uses 6 UInt32s as state. I need to come up with a reasonable way to seed it. Two obvious possibilities are: 1) generate 6 random numbers using System.Random and use them as seeds; 2) generate 2 Guids with Guid.NewGuid(). Which would be better? I do not need cryptographic security. ...

Port of Random generator from C to Java?

George Marsaglia has written an excellent random number generator that is extremely fast, simple, and has a much higher period than the Mersenne Twister. Here is the code with a description: good C random number generator I wanted to port the CMWC4096 code to Java, but it uses several unsigned datatypes so I am not sure how to do this ...

How to get random double value out of random byte array values?

I would like to use RNGCryptoServiceProvider as my source of random numbers. As it only can output them as an array of byte values how can I convert them to 0 to 1 double value while preserving uniformity of results? ...

Non-Linux Implementations of boost::random_device

Currently, Boost only implements the random_device class for Linux (maybe *nix) systems. Does anyone know of existing implementations for other OS-es? Ideally, these implementations would be open-source. If none exist, how should I go about implementing a non-deterministic RNG for Windows as well as Mac OS X? Do API calls exist in ei...

A random number generator that can get different numbers in < a second

I'm in need of a C++ (pseudo, i don't care) random number generator that can get me different numbers every time I call the function. This could be simply the way I seed it, maybe there's a better method, but every random generator I've got doesn't generate a new number every time it's called. I've got a need to get several random number...

Pros and cons of RNGCryptoServiceProvider

What are the pros and cons of using System.Security.Cryptography.RNGCryptoServiceProvider vs System.Random are. I know that RNGCryptoServiceProvider is 'more random', i.e. less predictable for hackers. Any other pros or cons? UPDATE: According to the responses, here are the pros and cons of using RNGCryptoServiceProvider so far: Pro...

How to create my own JavaScript Random Number generator that I can also set the seed

The JavaScript Math.random() function returns a random value between 0 and 1 (automatically seeded based on the current time (similar to Java I believe)). However I'd like to make a more robust function that accepts a min, a max, and (optionally) a seed. I found this code kicking around and it appears to work fine for getting a random ...

Seeding java.util.Random with consecutive numbers

I've simplified a bug I'm experiencing down to the following lines of code: int[] vals = new int[8]; for (int i = 0; i < 1500; i++) vals[new Random(i).nextInt(8)]++; System.out.println(Arrays.toString(vals)); The output is: [0, 0, 0, 0, 0, 1310, 190, 0] Is this just an artifact of choosing consecutive numbers to s...

What Type of Random Number Generator is Used in the Gaming Industry?

Given the extremely high requirements for unpredictability to prevent casinos from going bankrupt, what random number generation algorithm and seeding scheme is typically used in devices like slot machines, video poker machines, etc.? EDIT: Related questions: http://stackoverflow.com/questions/203382/do-stateless-random-number-generat...

Generating Uniform Random Deviates within a given range

I'd like to generate uniformly distributed random integers over a given range. The interpreted language I'm using has a builtin fast random number generator that returns a floating point number in the range 0 (inclusive) to 1 (inclusive). Unfortunately this means that I can't use the standard solution seen in another SO question (when th...

How good is java.util.Random?

Two Questions: Will I get different sequences of numbers for every seed I put into it? Are there some "dead" seeds? (Ones that produce zeros or repeat very quickly.) By the way, which, if any, other PRNGs should I use? Solution: Since, I'm going to be using the PRNG to make a game, I don't need it to be cryptographically secure. I'm ...

XKCD - Random Number

Could someone explain if and why the following random number function from XKCD works? I have never quite been able to understand it. I ask the question on SO hoping to find a more "human" explanation that could be understood by me. ...

C++. Is it possible that a RNG gives different random variable in two different machines using the same seed?

Hi everybody, I have this long and complex source code that uses a RNG with a fix seed. This code is a simulator and the parameters of this simulator are the random values given by this RNG. When I execute the code in the same machine, no matter how many attempts I do the output is the same. But when I execute this code on two differe...

How to manually generate random numbers

I want to generate random numbers manually. I know that every language have the rand or random function, but I'm curious to know how this is working. Does anyone have code for that? ...