As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [random]

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

Filter by
Sorted by
Tagged with
31 votes
4 answers

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 ...
Earlz's user avatar
  • 22.6k
14 votes
4 answers

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 ...
John Doucette's user avatar
0 votes
1 answer

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 (...
Louis Rhys's user avatar
  • 6,042
6 votes
4 answers

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 ...
Richard Rast's user avatar
14 votes
2 answers

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 ...
mahemoff's user avatar
  • 503
58 votes
5 answers

get weighted random item

I have, for example, this table +-----------------+ | fruit | weight | +-----------------+ | apple | 4 | | orange | 2 | | lemon | 1 | +-----------------+ I need to return a random ...
fl00r's user avatar
  • 691
5 votes
8 answers

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. ...
paul smith's user avatar
166 votes
11 answers

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 ...
dlras2's user avatar
  • 2,240
25 votes
7 answers

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 ...
HappyDeveloper's user avatar
4 votes
2 answers

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" ...
Nicole's user avatar
  • 28.1k
45 votes
14 answers

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 ...
KeithS's user avatar
  • 21.9k
11 votes
3 answers

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 ...
Talon876's user avatar
  • 211
33 votes
6 answers

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 ...
Paul Tomblin's user avatar
  • 1,939
39 votes
11 answers

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 ...
GordonM's user avatar
  • 6,285
54 votes
9 answers

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 ...
Vinoth Kumar C M's user avatar
4 votes
1 answer

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 = ...
Badr Hari's user avatar
  • 143
4 votes
1 answer

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 ...
Winston Ewert's user avatar
2 votes
1 answer

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?
Matt Bettinson's user avatar
28 votes
6 answers

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?
Korvin Szanto's user avatar
2 votes
1 answer

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,...
Nutel's user avatar
  • 1,491
10 votes
6 answers

I need a true random number generator web service [closed] 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 ...
Pacerier's user avatar
  • 4,943
24 votes
4 answers

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-...
Erik's user avatar
  • 508
45 votes
11 answers

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 ...
Magnus Wolffelt's user avatar

1 2