# Tagged Questions

This tag is for questions dealing with random numbers, pseudorandom numbers, and computer entropy.

21k views

### How should I test randomness?

Consider a method to randomly shuffle elements in an array. How would you write a simple yet robust unit test to make sure that this is working? I've come up with two ideas, both of which have ...
5k views

### How do functional languages handle random numbers?

What I mean about that is that in nearly every tutorial I've read about functional languages, is that one of the great things about functions, is that if you call a function with the same parameters ...
14k views

### Why is it impossible to produce truly random numbers?

I was trying to solve a hobby problem that required generating a million random numbers. But I quickly realized, it is becoming difficult to make them unique. I picked up Algorithm Design Manual to ...
5k views

### Unit-testing of inherently random/non-deterministic algorithms

My current project, succinctly, involves the creation of "constrainably-random events". I'm basically generating a schedule of inspections. Some of them are based on strict schedule constraints; you ...
5k views

### Random number generation algorithm for human brains? [closed]

Are you aware of, or have you devised, any practical, simple-to-learn "in-head" algorithms that let humans generate (somewhat "true") random numbers? By "in-head" I mean.. preferably without any ...
29k views

### UUID collisions [closed]

Has anybody done any real research on the probability of UUID collisions, especially with version 4 (random) UUIDs, given that the random number generators we use aren't truly random and that we might ...
3k views

### I'd like to write an “ultimate shuffle” algorithm to sort my mp3 collection

I'm looking for pseudocode suggestions for sorting my mp3 files in a way that avoids title and artist repetition. I listen to crooners - Frank Sinatra, Tony Bennett, Ella Fitzgerald etc. singing old ...
3k views

### Can you use Pi as a crude random number generator?

I recently saw this question over at math.SE. It got me thinking. Could Pi be used as a crude random number generator? I mean the results are well known(how long has pi been computed to now?) but, Pi ...
3k views

### Unit testing methods with indeterminate output

I have a class that is meant to generate a random password of a length that's also random, but limited to be between a defined min and max length. I'm constructing unit tests, and ran into an ...
7k views

### Predicting the output of PHP's rand()

I've read in numerous sources that the output of PHP's rand() is predictable as its a PRNG, and I mostly accept that as fact simply because I've seen it in so many places. I'm interested in a proof-...
5k views

### How to generate “language-safe” UUIDs?

I always wanted to use randomly generated strings for my resources' IDs, so I could have shorter URLs like this: /user/4jz0k1 But I never did, because I was worried about the random string generation ...
1k views

### Find out whose turn it is to buy the croissants, accounting for possible absences

A team has decided that every morning someone should bring croissants for everybody. It shouldn't be the same person every time, so there should be a system to determine whose turn it is next. The ...
2k views

### Since Garbage Collection is non-deterministic, why isn't it used for secure random number generation?

I get that /dev/random is a good source of entropy, and is what is usually used-- It's just as I'm reading up on GC, at least in Java, it seems accepted that the garbage collection daemon executes non-...
535 views

### What are best practices for testing programs with stochastic behavior?

Doing R&D work, I often find myself writing programs that have some large degree of randomness in their behavior. For example, when I work in Genetic Programming, I often write programs that ...
1k views

### Randomly generate directed graph on a grid

I am trying to randomly generate a directed graph for the purpose of making a puzzle game similar to the ice sliding puzzles from Pokemon. This is essentially what I want to be able to randomly ...
7k views

### I need a true random number generator web service [closed]

I need a way to get non-deterministic random numbers on demand for my application. However i do not wish/have the capabilities to build the hardware myself, thus I'm looking for a web service which ...
4k views

### rand() gives same numbers again for a small range

I'm trying to make sort of a game where I have a a grid of 20x20 and I display a player (P), a target (T) and three enemies (X). All these have an X and a Y coordinate which are assigned using rand(). ...
2k views

### Can a random number generator ever produce different output given identical seeds?

The title sums it up. I'm interested to know if there exists an algorithm capable of producing variable output given identical input without relying on other sources for randomness such as DateTime....
20k views

### How do random number generators work?

I was just pondering about php rand() function, and thinking about how I could remake it, and I came up completely stupified. How the heck do random number generators work?
5k views

### How Python random shuffle works?

How shuffle from random works in Python? I ask because it works very fast. When I try to write shuffle it works 1 minute for 10^6 element, but Python shuffle does that in 8 sec?
743 views

### Original source of `(seed * 9301 + 49297) % 233280` random algorithm?

If you search for examples of creating a seeded (pseudo)Random number generator, you will run into stuff like this (specific example http://indiegamr.com/generate-repeatable-random-numbers-in-js/): //...
338 views

### Random Cache Expiry

I've been experimenting with random cache expiry times to avoid situations where an individual request forces multiple things to update at once. For example, a web page might include five different ...
6k views

### random generator not good enough?

During an interview I was asked to implement a random generator in java without using any existing random number libraries that takes as an argument int n, and returns a random number between 0 and n. ...
977 views

### What is the difference between _Procedural Generation_ and _Random Generation_?

Today, I got into an argument about the term "procedural generation". My point was that its different from "classic" random generation in that procedural generation is based on a more mathematical, ...
3k views

### random unique pair numbers from two range

I want to write a function that return random unique pair numbers every time call it from a range until resetting it. Something like this: function randomUniquePairs(\$ranges, \$reset = false){ if (\$...
4k views

### How to generate random numbers without making new Random objects?

I'm using this as part of a game, but it's not really a game development question, so I'm putting it on this more general Stack Exchange. The goal is to generate "random" outputs for a fixed integer ...
351 views

### Determinism of functions using PRNG in Clojure and functional languages

I'm a bit surprised by a sentence found in the book "Clojure Programming" (1st [and only as I write this!?] edition), page 78: It should be obvious that it's impossible to deterministically test a ...
940 views

### Hash Algorithm Randomness Visualization

I'm curious if anyone here has any idea how the images were generated as shown in this response: Which hashing algorithm is best for uniqueness and speed? Ian posted a very well-received response but ...
1k views

### How to create a random generator

How could a random generator be implemented? I'm not speaking about the invocation of a language mathRandom() method, but the implementation of the routines that lead to generate numbers totally ...
556 views

### Why do we need a seed in Random Number Generators?

I want to know how Random number generator(RNG) works in any PL(Programming language). I know the random methods has short periods. i.e they start repeating the values after specific number of time. ...
607 views

### How to pick a random move/action/element non-probabilistically?

I am trying to create a simple AI that can play Go using Monte Carlo Tree Search. This question, however, is valid for all games where players take turns doing some action that, on average, reduce ...
340 views

### Is code that terminates on a random condition guaranteed to terminate?

If I had a code which terminated based on if a random number generator returned a result (as follows), would it be 100% certain that the code would terminate if it was allowed to run forever. while (...
1k views

### Randomization of biomes

You know how in Minecraft, the World is ever-expanding and all the biomes are randomized? My generalized question is: In relation to a space simulation that is also ever-expanding as the player moves ...
345 views

### random.choice in other languages

Python has a nice function in the standard library random.choice which returns a random element from a sequence. But none of the other languages I've developed in have thought to include such a ...
2k views

### Is there such a thing as truly random? [closed]

I saw a video about random numbers and how the programmer in that video was talking about computers generating pseudo random numbers and that they are not really random. I knew about this. Then he ...
514 views

### Choosing a random integer in a range such that it doesn't equal a particular number

Given an integer range and a number within that range, what's a reasonably robust and efficient way to randomly select a new number within the range such that it's not equal to the given number? ...
1k views

### Which of these two shuffle algorithms is more random?

Which of below two shuffle algorithms (shuffle1 and shuffle2) is more random? public final class Shuffle { private static Random random; public static void shuffle1(final Object[] array) { ...
839 views

### Why is the “period of a (pseudo)random number generator” important?

I've been trying to understand (pseudo)random number generator code from various sources and the concept of the period continues to elude me. To satisfy the minimum level of understanding, I've tried ...
2k views

### How does minecraft use a seed to generate a completely unique world?

In minecraft, before creating a world you have an option to input a seed. The algorithm takes the seed and creates a completely unique world. How does this work?
3k views

### Best way to choose random element from weighted list

I want to create a simple game. Every so often, a power up should appear. Right now the different kinds of power ups are stored in an array. However, not every power up should appear equally often: ...
1k views

### PHP rand function (or not so rand)

I was testing PHP rand function to write on a image. Of course the output shows that it's not so random. The code I used: <?php header('Content-Type: image/png'); \$lenght = 512; \$im = ...
102 views

### How specify acceptance criteria for randomness?

How would I express a Behavior Driven Development (BDD) acceptance criteria/story/scenario that indicates items should be random to some degree on a Home screen of an app like Instagram? Here's what ...
983 views

### Guid collisions

I have a product that lets game developers create games. Inside of their games they are required to give all the elements of their games GUIDs. I've told them that they need to generate their guids ...
887 views

### python random with a skew

I am trying to create a very simple evolution algorithm for a creature simulator, what I would like to have is, both creatures have a trait and a dominance level, both noted by ints. their child's ...
399 views

### is Microsoft LC random generator patented?

I need a very simple pseudo random generator (no any specific quality requirements) and I found Microsoft's variant of LCG algorithm used for rand() C runtime library function fit my needs (gcc's one ...
146 views

### Randomness of wrapped RNG

There are plenty of questions around regarding random number generation, but I couldn't find anything that exactly matched my question. Apologies if I missed one. Most random number generators in ...
361 views

### Whether to store all numbers or just their ranges in database for this application

I'm developing a (PHP MySQL) Web App which will sell dynamically generated real time cell phone numbers for cellular companies. A company will ask for, say, a thousand numbers and this app will check ...
162 views

### Defining a random “safe” path for a game character

I am writing a game in Java and it can be likened to the recently popular game "Flappy Bird" in the sense that the character moves up and down and the users touch and must avoid the obstacles. The ...