Tasks involving random numbers and/or output.

learn more… | top users | synonyms

13
votes
33answers
3k views

Death By Shock Probe: That's a lot of dice

In the webcomic Darths & Droids, Pete, who plays R2-D2 in the fictional roleplaying campaign around which the comic is based, once claims (warning: potential spoilers in the linked comic) that, ...
9
votes
4answers
558 views

Theseus' New Ship

The Ship of Theseus is an old question that goes something like: If a ship has had all of its original parts replaced, is it still the same ship? For this golf, we're going to slowly replace ...
18
votes
13answers
2k views

Random Golf of the Day #4: The Bertrand Paradox

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
12
votes
4answers
631 views

Draw a Random Walk with Slashes

Write a program or function that takes in a positive integer N (via stdin/command line/function arg) and prints or returns a string representation of a two dimensional random walk that is N steps ...
0
votes
0answers
63 views

Random arithmetic quiz [duplicate]

Given a and b as two random numbers from 0 to 10 and op as a random symbol of arithmetic operations, you should display 10 questions in the format: a op b = to the user, after each question if the ...
-4
votes
5answers
120 views

Generate a random floating point number between 2 limits [closed]

This challenge is to generate a random floating-point number between 2 limits. You may use any language so long as it can be called from the command line, and runs on linux. It must also be able to ...
5
votes
1answer
494 views

Drawing an Image Based on a Trace of its Hue

Introduction Local genius Calvin's Hobbies recently challenged us to trace the hue of an image. It is recommended to read his challenge beforehand, but to highlight the main points: The trace of ...
12
votes
21answers
2k views

Monte Carlo estimator of Pi

Happy Pi Day everyone! For no reason at all, I'm trying to construct a Monte Carlo estimator of Pi that is as short as possible. Can we construct one that can fit in a tweet? To clarify, what I have ...
3
votes
17answers
863 views

Randomised list, formatted nicely

Challenge Task Given a number N, output 2 NxN squares; each line of each square is a random permutation of [0, N); the squares are separated by a newline Rules Produce a randomised list of length ...
-5
votes
1answer
202 views

Code golf: Dice Simulator

Task A game uses dice with 4, 6 and 12 sides to determine various outcomes. The user should be able to input which dice is being thrown, eg 4, 6 or 12. The program should output the dice chosen and ...
13
votes
4answers
361 views

Rubik's Cube Scrambles

Your task is to create a random sequence of moves, which can be used to scramble a Rubik's Cube. Such a scramble is made up of exactly 25 moves. Each move consist of of the letters UDRLFB optionally ...
13
votes
11answers
1k views

Random Golf of the Day #3: Integer Partitions

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
10
votes
22answers
1k views

Random Golf of the Day #2: Numbers from a Normal Distribution

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
20
votes
32answers
4k views

Random Golf of the Day #1: Shuffle an Array

About the Series I will be running a little series of code-golf challenges revolving around the theme of randomness. This will basically be a 9-Hole Golf Course, but spread out over several ...
13
votes
18answers
2k views

Generate any random integer

Your program/function should output exactly one integer output any integer with positive probability output an integer greater than 1.000.000 or less than -1.000.000 with at least with 50% ...
9
votes
1answer
228 views

tiny diamond square algorithm

The diamond square algorithm is a fractal terrain (heightmap) generating algorithm. You can find some nice description how it works here: http://www.gameprogrammer.com/fractal.html (Used as a ...
23
votes
2answers
432 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. ...
20
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
172 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
638 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 ...
102
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
799 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> ::= ...
14
votes
4answers
521 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 ...
13
votes
5answers
1k 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
621 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
123 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
1k 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: ...
23
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 ...
8
votes
10answers
648 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
623 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
711 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
619 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 ...
46
votes
42answers
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
764 views

Generate ASCII wilderness map [closed]

Generate an ASCII wilderness map. Example output: ................^^^^ ..................^^ ...^^^^........o.... .....^^^^........... .................... ........o....TT..... ..TTTT.............. ...
4
votes
1answer
875 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
902 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
387 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 ...
40
votes
56answers
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
4k 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
3k 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
628 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 ...
16
votes
5answers
850 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 ...