Tasks involving random numbers and/or output.

learn more… | top users | synonyms

22
votes
2answers
328 views

Implement a PCG

What better problem for PCG.SE than to implement PCG, A Better Random Number Generator? This new paper claims to present a fast, hard-to-predict, small, statistically optimal random number generator. ...
18
votes
7answers
1k views

Reassuring parables

Quite a few people here are probably avid XKCD readers. So, I figure I'd challenge you guys to do something that Megan can do easily: make a script that generates thousands of reassuring parables ...
-2
votes
7answers
150 views

Create an array of unique ints in a set range

Goal: Write a piece of code that produces a array containing all integer values in a set range in random order (upper and lower bounds included). Use any language you like, but use as little built-in ...
43
votes
18answers
6k views

Improvise a Hardware Random-Number Generator

Your task is to improvise a hardware random-number generator with whatever hardware you have lieing around. Challenge Write a program with the following properties: It prints either 0 or 1 (and ...
12
votes
29answers
2k views

Randomly pick one number that is different than two other random numbers

Two random numbers A and B have been generated to be either 1, 2, or 3 your job is to randomly pick a third number C that can also be 1,2 or 3. But, C cannot equal A or B. And Yes, A can equal B. ...
5
votes
7answers
622 views

Generate four type-4 GUIDs for me

The type 4 GUID is described by Wikipedia, quoth: Version 4 UUIDs use a scheme relying only on random numbers. This algorithm sets the version number (4 bits) as well as two reserved bits. All ...
97
votes
63answers
16k views

Random script that isn't actually random

As a little joke in the office someone wanted a script that randomly picks a name, and said person will make a round of drinks. Let's call the people John, Jeff, Emma, Steve and Julie. I thought it ...
6
votes
3answers
1k views

Super fast sampling from a tricky random distribution

This is a micro-optimization challenge. The task is to sample from the maximally skewed stable distribution F(x;1,-1,Pi/2,0). See Table 1 of http://arxiv.org/pdf/0908.3961v2.pdf . It is easiest to ...
5
votes
6answers
629 views

Generate random PESEL number

From Wikipedia: PESEL is the national identification number used in Poland since 1979. It always has 11 digits, identifies just one person and cannot be changed to another one. It has ...
18
votes
13answers
2k views

Roll Dungeons and Dragons dice

I want to play Dungeons and Dragons, but I don't have any dice! Your challenge is to roll some D&D dice. The input format specification in Backus-Naur form is: <valid-input> ::= ...
13
votes
4answers
505 views

Taking the dog for a walk

My dog is barking at me, but I'm too lazy to take him for a walk. I have an idea! I'll get the people at Code Golf to do it for me! Your challenge is to simulate a dog's walk. Here are the rules for ...
10
votes
5answers
976 views

Generate white noise

The challenge is: generate an audio file made of white noise. Requirements and instructions: Your program must generate an audio file containing only white noise, meaning its intensity is the same ...
2
votes
15answers
575 views

Random number generation, without built-in random number generation libraries [duplicate]

Task: Make a random number generator. The catch is that you can't use any built-in randomness functions. Your random numbers must be anything between 0 and 100, though they do not have to be floating ...
-1
votes
1answer
120 views

Password Generator [duplicate]

Task: Make a program that generate a 24-digit password. Rule: None of the character can be repeated more than once Must include at least one upcase, one locase, one number, five special ...
36
votes
37answers
6k views

Random Password Generator

The domain server requires that all employees have a strong, random password conforming to the following rules: Exactly 15 characters long. Keyboard-typeable characters only (as shown in code-type ...
6
votes
6answers
823 views

Random CSS Color code

This blog post about generating random CSS color codes in JavaScript have multiple solutions for generating a random color in JavaScript. The shortest I can find is this: ...
22
votes
6answers
4k views

Build a random number generator that passes the Diehard tests

While there are many code golf questions on here involving randomness, I haven't seen one yet that actually asks for building an algorithmic pseudorandom number generator. There's this one that asks ...
7
votes
10answers
597 views

Non-transitive dice game

Those of you who like Numberphile would be familiar with Dr. James Grime, who described a non-transitive dice game on his channel. The game consists of three 6-faced dice: Die 1: 3,3,3,3,3,6 Die 2: ...
3
votes
14answers
601 views

Rolling three dice and show the probabilities

Roll 3 dice, count the two highest two values and add them to the result. Every 1 must be rolled once again. Now show the average throw after 1000000 tries and the probabilities for each result ...
8
votes
7answers
691 views

Output a shuffled deck using random input

Input/Output: Input: A uniformly random, infinitely long, string of '0's and '1's, taken from stdin. The string is assumed to be truly random, not pseudo-random. It is uniform in that each ...
5
votes
8answers
545 views

Dice from Changing Random Generator

Introduction You are given a random integer generator with the following implementation The first invocation always returns 1. The second invocation returns a random integer between 1 and 2. The ...
44
votes
36answers
5k views

Can you Golf Golf?

You are required to generate a random 18-hole golf course. Example output: [3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4] Rules: Your program must output a list of hole lengths for exactly 18 holes Each ...
11
votes
11answers
1k views

Generate a (completely deterministic) pseudorandom bit stream

Inspired by Random with your hands tied: The Goal The goal of this challenge is to write a program that generates a pseudorandom bit stream, which is a string of 1s and 0s that appears to be ...
9
votes
6answers
692 views

Generate ASCII wilderness map

Generate an ASCII wilderness map. Example output: ................^^^^ ..................^^ ...^^^^........o.... .....^^^^........... .................... ........o....TT..... ..TTTT.............. ...
4
votes
1answer
801 views

Lorem Ipsum Random Code Generation

An IDE developer has hired you to write a program that generates (by printing to stdout) n lines of randomly generated code. They will use your program to create sample code for use in marketing their ...
7
votes
3answers
866 views

Did I win the lotto?

I just submitted an answer to this question, and then looked about at some news stories about the MegaMillions lottery craze going on right now in the US. This news article stated that an individual ...
6
votes
12answers
5k views

Random sampling without replacement

Create a function that will output a set of distinct random numbers drawn from a range. The order of the elements in the set is unimportant (they can even be sorted), but it must be possible for the ...
-6
votes
1answer
378 views

Most Creative “Sex Panther” Script [closed]

Taking inspiration from Anchorman. Write a script in the style of Sex Panther cologne: "60% of the time, it works every time" You can interpret this anyway you would like. Highest voted answer ...
38
votes
51answers
4k views

How to randomize letters in a word

According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod. So, for fun, what would be ...
16
votes
30answers
3k views

Draw dice results in ASCII

Show the random result of a dice toss if done with a cube shaped die, in ASCII. $ dice should result in one of ----- | | | o | | | ----- ----- |o | | | | o| ----- ----- |o | | o | | ...
10
votes
15answers
2k views

Shuffle a deck without local variables

The object of this puzzle is to take a deck of 52 cards and shuffle it so that each card is in a random position. Given: An array, deck, of 52 distinct integers representing the cards. When you ...
18
votes
69answers
8k views

How to write a single-line password generator [closed]

Is there a way of writing a password generator in only one line? The password should consist of 8 random chars out of a-z, A-Z and 0-9. It should also return a different password every-time. Also, ...
8
votes
13answers
603 views

Random dice tipping

In a standard dice (die) the numbers are arranged so that opposite faces add to seven. Write the shortest possible program in your preferred language which outputs a random throw followed by 9 random ...
14
votes
4answers
685 views

Fix a broken random function

A friend has an add-on card in their computer which generates a perfectly random number from 1 to 5 inclusive. Unfortunately, they spilt cola on it somehow, and it now generates only 2's for all ...
12
votes
10answers
817 views

Forecast the weather

Write the shortest program to forecast the weather for the next 7 days The input (from stdin) is the weekday and the season The output (to stdout) is seven lines weekday and the temperature in ...
28
votes
32answers
6k views

Rand5() to Rand7()

You are provided with a function Rand5(). This function returns perfectly random (equal distribution) integers between 1 and 5. Provide the function Rand7(), which uses Rand5() to produce perfectly ...