Questions tagged [random]

Tasks involving random numbers and/or output.

Filter by
Sorted by
Tagged with
107
votes
65answers
20k 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 ...
103
votes
16answers
4k views

Simulate the Universe!

One nice property of a Turing-complete language is that it can be used to write any program, up to and including the simulation of the entire Universe. Your job is to do exactly that: write a program ...
80
votes
103answers
16k views

Shortest code to produce non-deterministic output

You need to produce output that is non-deterministic. In this case, this will be defined to mean that the output will not always be the same result. Rules: A pseudo-random number generator that ...
65
votes
41answers
4k views

Golfing A Weasel Program

Richard Dawkins in his book The Blind Watchmaker, describes a Weasel program. The algorithm can be described as follows: Start with a random string of 28 characters. Valid characters are all ...
58
votes
49answers
10k views

A game of dice, but avoid number 6

Tournament over! The tournament is now over! The final simulation was run during the night, a total of \$3*10^8\$ games. The winner is Christian Sievers with his bot OptFor2X. Christian Sievers also ...
57
votes
117answers
14k views

Duck, duck, goose!

Remember the kids game, 'Duck, Duck, Goose'? No? Me neither. The challenge Print the word 'duck' on individual lines an indeterminate amount of times. Print the word 'goose'. Your program ends. The ...
57
votes
42answers
4k views

Alex-style Addition

Inspired by Alex's glorious Learn you an R for great good, we are going to humbly recreate Alex's "one true R program" -- but with a twist. Alex-style Addition works like this -- it has a 90% chance ...
57
votes
27answers
6k views

Cracking in progress

Remember those brute-force programs to crack password that show every combination they are trying? More precisely, at one point, the n first characters are fixed (they have been guessed successfully), ...
55
votes
74answers
6k 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 ...
53
votes
47answers
6k 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 ...
53
votes
19answers
7k 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 ...
52
votes
24answers
4k views

Do X without Y​

Usually, it is said that "Doing X without Y" can be a trap to beginners writing challenges (source). However, I am cocky and think that I can definitely make an X without any Ys. Randomly. Oh yes, ...
50
votes
10answers
9k 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 ...
47
votes
54answers
4k views

Random Golf of the Day #7: A distinctly random character

About the Series This is a guest entry for the Random Golf of the Day series. First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all....
47
votes
48answers
7k views

Display random colored pixels

I've always liked screens full of randomly colored pixels. They're interesting to look at and the programs that draw them are fun to watch. The challenge Fill your screen, or a graphical window, ...
47
votes
46answers
15k views

99 bugs in the code

99 bugs in the code The adaption of "99 bottles of beer on the wall" for computer science where the bugs increase instead of the bottles decreasing is often re-posted around the internet. Example T-...
44
votes
12answers
2k views

Scramble words while preserving their outlines

This is much more advanced than How to randomize letters in a word and Cambridge Transposition because of the rule about which letters may be swapped with which. A simple regex will not suffice here. ...
43
votes
24answers
8k views

Chaos is an ASCII ladder

You know nothing The things I do for "Chaos is a ladder" is a memorable line from the television series Game of Thrones. The purpose of this challenge is to build a ladder from chaos, in ASCII art. ...
42
votes
26answers
3k views

Sheffle tho vawols ureund!

Given an input string, output that string with all vowels a, e, i, ...
41
votes
21answers
5k views

EASY to memorize numbers

Numbers that are easy to remember yet theoretically not easily made Your challenge is to make a program/function in any language that generates uniformly random numbers that fit these criteria: ...
40
votes
38answers
7k views

This will eventually stop…

Given an input string S, print S followed by a non-empty separator in the following way: Step 1: ...
40
votes
36answers
9k 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 ...
39
votes
22answers
3k views

Natural Pi #0 - Rock

Goal Create a program/function that takes an input N, check if N random pairs of integers are relatively prime, and returns <...
39
votes
19answers
4k views

Create a solar system

Intro This is based on an actual problem I recently faced while making a computer game and I thought it would make for a nice round of code-golf. There are seven main spectral classes of star which ...
35
votes
38answers
7k views

That's a lot of monkeys

The infinite monkey theorem states that, given infinite time, a machine sending an endless stream of random characters will always type any given text. That sounds to me like a great idea for a ...
35
votes
52answers
5k views

Random Capitalization

The Task Your task is to create a program or a function that, given an input, outputs the input text with random letters capitalized, while keeping already capitalized letters capitalized. Every ...
35
votes
35answers
6k 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 questions....
35
votes
9answers
4k views

Quixels - Quantum Pixels

Introduction A quixel is a quantum pixel. Similar to a classical pixel, it is represented with 3 integer values (Red, Green, Blue). However, quixels are in a super position of these 3 states instead ...
34
votes
48answers
10k views

Code Golf: Your own pet ASCII snake

So, I wrote myself a one-liner which printed out a snake on the console. It's a bit of fun, and I wondered how I might condense my code... Here's a (short) example output: ...
34
votes
32answers
6k views

Create a Magic 8 Ball

As a child, my friend had a magic 8 ball that we would ask questions to and see what the fate of that question was. Challenge Your challenge is to write a program (or function) that when run (or ...
34
votes
28answers
6k views

Choose The Powerball Numbers!

Powerball is an American lottery that has recently gained attention because the current jackpot (as of January 11, 2016) is the largest lotto prize in history, at about $1.5 billion (USD). Powerball ...
34
votes
29answers
2k views

Crazy 8s Code Golf

Create a program that prints all whole numbers inclusively between an interval (a, b), and replaces multiples of 8 in the sequence with random (uniformly ...
32
votes
32answers
4k views

Russian Roulette, Reloaded

Let's play Russian Roulette! Normally, this would be a race to write the shortest MOD 6 program, but that's not very realistic, as the chance of winning decreases with each click. Here are the rules: ...
32
votes
21answers
7k views

What surrounds my Minesweeper tile?

Minesweeper is a puzzle game where mines are hidden around a board of nondescript tiles with the goal of identifying the location of all mines. Clicking on a mine loses the game, but clicking on any ...
31
votes
50answers
4k views

Simulating Exploding Dice

Your task is to make a program that takes in an integer n > 1, and outputs the roll of a single n-sided die. However, this ...
31
votes
27answers
5k views

Passwordify the string

Your challenge is to passwordify the string! What is passwordifying, you ask? Take a string as input. This string will only contain uppercase letters, lowercase letters, digits, and spaces. You ...
31
votes
11answers
2k views

Generate a “GitHub” Avatar

Background / Description Note: as @HelkaHomba points out, the actual GitHub identicons are not actually random but based on the hash of a username The default GitHub avatar is a 5x5-pixel image. A ...
31
votes
22answers
2k views

Make it rain characters

Inspired by this chat mini-challenge. Given a string as input (ASCII printable characters only), output the string with the letters "raining" down. Each letter must be a random number of lines ...
31
votes
3answers
1k 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. ...
30
votes
43answers
3k views

Generating a random alphanumeric string of length N

What is the shortest way of generating a random string with a given length and with only alphanumeric characters allowed? example of a random string: with N = 9 output would be ...
30
votes
21answers
2k views

Generate a random derangement

Challenge description A "derangement" of a sequence is a permutation where no element appears in its original position. For example ECABD is a derangement of ...
30
votes
3answers
520 views

The Drunken Typist

Background A typist comes home wfter some riugh drinkinh and realizes thag an importsnt letter still needs to be wtitten. To make sure he vets the text correct, he writes the text character bh ...
29
votes
70answers
8k views

Randomizing until 0

Challenge Sandbox post Given a positive integer (K) Output a uniformly-random integer (Y) between ...
29
votes
27answers
5k views

Code Golf: Your own horizontal pet ASCII snake

Very heavily inspired by this challenge Code Golf: Your own pet ASCII snake - I thought making it horizontal would add an extra layer of complexity. An example horizontal snake: ...
29
votes
31answers
14k views

Rand5() to Rand7() [closed]

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 ...
29
votes
20answers
3k views

Implement Homestuck's Catenative Doomsday Dice Cascader

Challenge I'm under attack by the larcenous Midnight Crew and I need to summon the Catenative Doomsday Dice Cascader in order to defend myself. Since I'm low on space, I need the code to be as short ...
29
votes
11answers
3k views

Random numbers with fixed sum

Your task is to write a program or a function that outputs n random numbers from interval [0,1] with fixed sum s. Input ...
28
votes
46answers
3k views

1/N probability

Because there are not enough simple code-golf challenges: Create an optionally unnamed program or function that, given (by any means) an integer 1 ≤ N ≤ 10000, outputs your language's True value with ...
28
votes
30answers
3k views

Person of Interest

Background Person of Interest is a crime drama on CBS, and my favorite TV show, as of late. The show is about a man named Harold Finch, a billionaire programmer, and his partner John Reese, a ...
28
votes
23answers
3k views

Basic sort, with annoying bug

Your input is a list/sequence/vector/array of 5-255 positive integers, not necessarily unique. You may assume whatever input format is most suitable, and that each integer (as well as the quantity of ...