Questions tagged [random]
This tag is for questions dealing with random numbers, pseudorandom numbers, and computer entropy.
123
questions
31
votes
4
answers
6k
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 ...
14
votes
4
answers
1k
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 ...
0
votes
1
answer
129
views
How to test a random-generating feature in application? [duplicate]
Possible Duplicate:
How should I test randomness?
One of the features to be developed in our application was allowing user to click a button which will choose an element at random out of (...
6
votes
4
answers
11k
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 ...
14
votes
2
answers
1k
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 ...
58
votes
5
answers
54k
views
get weighted random item
I have, for example, this table
+-----------------+
| fruit | weight |
+-----------------+
| apple | 4 |
| orange | 2 |
| lemon | 1 |
+-----------------+
I need to return a random ...
5
votes
8
answers
10k
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. ...
166
votes
11
answers
92k
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 ...
25
votes
7
answers
14k
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 ...
4
votes
2
answers
3k
views
What's a good algorithm for a random, uneven distribution of a fixed amount of a resource?
Problem
I have X, a positive integer, of some resource, R.
There are N potential targets.
I want to distribute all of R to the N targets in some "interesting" way.
"Interesting" ...
45
votes
14
answers
10k
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 ...
11
votes
3
answers
2k
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 ...
33
votes
6
answers
134k
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 ...
39
votes
11
answers
9k
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 ...
54
votes
9
answers
70k
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 ...
4
votes
1
answer
2k
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 = ...
4
votes
1
answer
444
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 ...
2
votes
1
answer
4k
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?
28
votes
6
answers
116k
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 do random number generators work?
2
votes
1
answer
95
views
Random number for HTTPS MAC
Recently I found that Netscape used quite simple algorithm to generate random number for Message Authentication Code to establish an HTTPS connection (Nestscpe used time, process identification number,...
10
votes
6
answers
11k
views
I need a true random number generator web service [closed]
Random.org provides 200k free random bits (only 6250 32-bit integers!) from the analog world (cf.) per IP per day.
Does anyone know of an alternative web service that provides more on-demand random ...
24
votes
4
answers
14k
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-...
45
votes
11
answers
13k
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 ...