Questions tagged [random]

Tasks involving random numbers and/or output.

Filter by
Sorted by
Tagged with
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....
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
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, ...
21
votes
17answers
1k views

Cambridge Transposition

I'm sure most, if not all, of you have come across this at some point or another: Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the ...
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 ...
21
votes
5answers
2k views

Random ASCII Art of the Day #5: Diamond Tilings

Mash Up Time! This is instalment #5 of both my Random Golf of the Day and Optimizer's ASCII Art of the Day series. Your submission(s) in this challenge will count towards both leaderboards (which you ...
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 ...
42
votes
26answers
3k views

Sheffle tho vawols ureund!

Given an input string, output that string with all vowels a, e, i, ...
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 ...
19
votes
11answers
2k 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 ...
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: ...
17
votes
12answers
2k views

Shamir's Secret Sharing

Given n (the number of players), t (the threshold value), and s (the secret), output the <...
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 ...
20
votes
43answers
4k 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, ...
14
votes
20answers
1k 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 ...
8
votes
7answers
481 views

Generating Word Grids

Given input n, produce a word grid of size n, in as few bytes as possible. Details The number provided will always be odd. The ...
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 <...
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
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: ...
30
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
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 ...
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, ...
24
votes
35answers
4k 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 ...
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 ...
23
votes
18answers
2k views

Print a shuffled deck of cards

Input None Output 52 cards. No duplicates. Cards are represented as their unicode characters, e.g. 🂹. The Unicode codepoints follow the following format: The first three digits are ...
22
votes
9answers
884 views

<(“<) Bird Dancer (>”)>

Your bird has been itching for some exercise and is sick of being stuck in static positions all the time. Write a program that will show a randomly dancing ascii bird, updating every 100ms*n or 200ms*...
15
votes
38answers
3k views

Generate random UUID

I need a UUID. Your job is to generate one. The canonical UUID (Universally Unique IDentifier) is a 32 digit hexadecimal number with hyphens inserted in certain points.The program should output 32 ...
23
votes
16answers
1k views

Random Golf of the Day #8: Shuffle an infinite list

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 ...
17
votes
20answers
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% ...
14
votes
13answers
2k views

Computer Cipher

Introduction: I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too ...
1
vote
15answers
2k 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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
20
votes
13answers
3k 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: ...
21
votes
3answers
739 views

Randomize the test

I'm a teacher, and in a few days I have to give my students a test. Now, I'm always worried about my loveliest students being hurt by the least loveliest ones when they cheat, so I want to randomize ...
29
votes
70answers
8k views

Randomizing until 0

Challenge Sandbox post Given a positive integer (K) Output a uniformly-random integer (Y) between ...
21
votes
39answers
2k 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 ...
27
votes
7answers
2k 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 ...
27
votes
9answers
4k views

Map a random number to pi

A double precision representation of a decimal can only guarantee an accuracy of 15 decimal places, thus pi is approximated as: 3.141592653589793 You can see ...
23
votes
14answers
2k views

Make a Bubble-wrap simulator

Bubble-wraps are maximum-level entertainment. Everyone can agree to that. Now, you will make even computers enjoy bubble-wraps. Specs You will be given two integers, w, and h.(each are responsively ...
18
votes
5answers
720 views

Generate an ascii-art non-intersecting path

Given 2 integer inputs representing the size of the field, x and y, output a path through the field. Example output for ...
12
votes
25answers
2k 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 ...
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 ...
24
votes
15answers
1k views

The Random Walker Printer

Draw a program or function that will write to STDOUT n times (each for one step) a string that contains a dot ...
21
votes
16answers
4k views

Bitstring Physics

Background Yes, bitstring physics is a real thing. The idea is to construct a new theory of physics using only strings of bits that evolve under a probabilistic rule... or something. Despite reading ...
16
votes
18answers
5k views

Simplistic Lava Lamp

Introduction: I think everyone knows what a Lava Lamp is, but in case they do not: (Image source) They're basically glass tubes that contain wax in a translucent liquid. The bottom part is heated ...
16
votes
27answers
3k views

Generate a pronounceable word

The challenge is simple: generate a word. Specifications: Word must be pronounceable. This is defined as "alternating between a consonant and a vowel." A consonant is one of the following letters: ...