Questions tagged [random]

Tasks involving random numbers and/or output.

Filter by
Sorted by
Tagged with
106 votes
65 answers
21k 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 ...
TMH's user avatar
  • 1,283
106 votes
16 answers
6k 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 ...
vsz's user avatar
  • 8,137
104 votes
134 answers
20k 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 ...
mbomb007's user avatar
  • 23.4k
68 votes
42 answers
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 ...
Noelkd's user avatar
  • 1,045
68 votes
31 answers
5k 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, ...
Conor O'Brien's user avatar
65 votes
125 answers
17k 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 ...
AJFaraday's user avatar
  • 11.8k
61 votes
91 answers
13k views

Implement Minceraft

Introduction The game Minecraft has a 1 in 10000 chance of showing "Minceraft" instead of "Minecraft" on the title screen. Your challenge Your challenge is to code a function or ...
emanresu A's user avatar
  • 37.8k
59 votes
82 answers
8k 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 ...
Tomalak's user avatar
  • 941
59 votes
51 answers
5k 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 ...
a spaghetto's user avatar
  • 11.2k
57 votes
49 answers
11k 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 ...
maxb's user avatar
  • 6,887
57 votes
27 answers
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), ...
Dada's user avatar
  • 8,473
55 votes
49 answers
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 ...
mikera's user avatar
  • 1,273
54 votes
62 answers
5k 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....
trichoplax is on Codidact now's user avatar
52 votes
47 answers
17k 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. ...
Sam Dean's user avatar
  • 718
51 votes
19 answers
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 ...
Wrzlprmft's user avatar
  • 2,920
51 votes
11 answers
10k 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 ...
Joe Z.'s user avatar
  • 34.9k
49 votes
50 answers
19k 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, ...
MD XF's user avatar
  • 13.9k
47 votes
28 answers
4k views

Simulate reproduction in a population of oozes

Reproductive strategy of oozes can be summarized as follows: o O 8 oo A population of oozes at generation N is described by a string, for example: ...
anatolyg's user avatar
  • 13.6k
45 votes
82 answers
5k views

Print random integers until 0

You are to write a program which generates random integers between \$0\$ and \$99\$ inclusive, outputting each integer in turn, until \$0\$ is generated. You may choose which single-order random ...
caird coinheringaahin g's user avatar
45 votes
44 answers
8k views

This will eventually stop…

Given an input string S, print S followed by a non-empty separator in the following way: Step 1: ...
Fatalize's user avatar
  • 38.7k
45 votes
16 answers
3k 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. ...
Adám's user avatar
  • 30.2k
44 votes
26 answers
10k views

Random point on a sphere

The Challenge Write a program or function that takes no input and outputs a 3-dimensional vector of length \$1\$ in a theoretically uniform random direction. This is equivalent to a random point on ...
Jitse's user avatar
  • 7,016
43 votes
24 answers
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 ...
Luis Mendo's user avatar
  • 104k
42 votes
21 answers
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: ...
drham's user avatar
  • 525
41 votes
69 answers
6k 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 ...
Brecert's user avatar
  • 437
41 votes
26 answers
3k views

Sheffle tho vawols ureund!

Given an input string, output that string with all vowels a, e, i, ...
Fatalize's user avatar
  • 38.7k
40 votes
37 answers
11k 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 ...
Hand-E-Food's user avatar
  • 8,730
39 votes
18 answers
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 ...
Absinthe's user avatar
  • 509
38 votes
58 answers
3k views

Output a random unary string

Your task is simple: output the letter x a random number of times. Every possible length of xs must have a non-zero probability ...
pxeger's user avatar
  • 23.7k
38 votes
23 answers
4k 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 <...
NonlinearFruit's user avatar
37 votes
73 answers
9k views

Randomizing until 0

Challenge Sandbox post Given a positive integer (K) Output a uniformly-random integer (Y) between ...
Luis felipe De jesus Munoz's user avatar
37 votes
31 answers
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 ...
GracefulLemming's user avatar
36 votes
68 answers
4k views

10 PRINT CHR$(205.5+RND(1)); : GOTO 10 in PHP (or anything else, for that matter)

Just had a 'spirited' conversation with a co-worker about the succinctness of the following BASIC statement: 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 It's the title ...
Judy's user avatar
  • 487
36 votes
54 answers
6k 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 ...
Riker's user avatar
  • 7,840
36 votes
30 answers
6k 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 ...
Daniel's user avatar
  • 6,719
35 votes
51 answers
11k 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: ...
AJFaraday's user avatar
  • 11.8k
35 votes
33 answers
10k 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 ...
DevelopingDeveloper's user avatar
35 votes
40 answers
8k 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 ...
LyricLy's user avatar
  • 3,673
35 votes
59 answers
6k views

Russian Roulette

Write a program which plays Russian Roulette! If the program is started, there should be a 5 in 6 chance of it ending normally after printing "I survived!" there should be a 1 in 6 chance of the ...
vsz's user avatar
  • 8,137
35 votes
35 answers
7k 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....
Martin Ender's user avatar
35 votes
54 answers
4k 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 ...
m13r's user avatar
  • 455
34 votes
36 answers
8k views

The cat ate your input again!

Create a cat program, a.k.a a program that takes an input and prints it. ...Except, the program will randomly take characters away from your input and print that instead. Each character in the input ...
AndrewTheCodegolfer's user avatar
34 votes
9 answers
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 ...
NonlinearFruit's user avatar
34 votes
11 answers
5k 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 ...
Angs's user avatar
  • 4,987
33 votes
49 answers
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 ...
Adám's user avatar
  • 30.2k
33 votes
13 answers
5k 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 ...
MCMastery's user avatar
  • 833
32 votes
28 answers
7k 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 ...
Calvin's Hobbies's user avatar
32 votes
24 answers
3k views

Generate a Nine-Ball Pool rack

Introduction Nine-Ball is a popular pool game played casually and as a competitive sport. There is one of each numbered ball, with the numbers 1 to 9. The game starts with all 9 of the balls in a ...
nihilazo's user avatar
  • 517
32 votes
28 answers
3k views

Implement the Zundoko Kiyoshi function

Background The Zundoko Kiyoshi function originates from this tweet by kumiromilk. Translated from Japanese, it reads roughly as follows: The test for my Java lecture had a problem that said "...
sporeball's user avatar
  • 1,656
32 votes
31 answers
16k 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 ...
Dan McGrath's user avatar
  • 1,017

1
2 3 4 5
7