The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [random]

Tasks involving random numbers and/or output.

Filter by
Sorted by
Tagged with
23
votes
30answers
4k views

Make a haystack (with a needle)

(Essentially the inverse of Find the needle in the haystack) Given two tuples, (w, h) and (x, y), generate a haystack composed ...
21
votes
8answers
3k views

Rational Number RNG

The Objective Build a random number generator whose range is \$\left[0,1\right) \cap \mathbb{Q} .\$ This is, build a random number generator that can produce any value that's: at least \$0 \,;\$ ...
1
vote
15answers
307 views

type in a random mess of capital letters [duplicate]

SOMe PEOPle lIkE tO TYpE iN A LoGiCAL MAnNER, WITh CapITals aT tHe bEGiNnIng Of ThE SENtENCE and smaLl LETTErS EVeRYWHErE eLsE. NOT Us. NOt Us. Your joB iS to tAkE A SenTEncE Of A LL SMAlL LeTTeRS, ...
23
votes
23answers
3k views

Fill a bowl with alphabet soup

We seem to never get tired of alphabet-related challenges... The recipe Given a string of letters S, and two positive integers ...
31
votes
21answers
6k views

Random point on a sphere

The Challenge Write a program or function that takes no input and outputs a vector of length \$1\$ in a theoretically uniform random direction. This is equivalent to a random point on the sphere ...
17
votes
15answers
3k views

I multiply the source, you (probably) multiply the output!

Task The task is to write a program that outputs a consistent but otherwise arbitrary positive integer \$x\$ (so strictly greater than 0). Here's the catch: when the source is repeated \$N\$ times (...
30
votes
34answers
7k 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 ...
15
votes
14answers
2k views

Generate a random point outside a given rectangle within a map

Introduction Given this visualization of a playing field: ...
8
votes
1answer
192 views

Compute my Sacred Geometry [closed]

In the tabletop RPG named Pathfinder, there is a feat that characters can take called Sacred Geometry, which allows a character who has it to buff their spells in exchange for doing some math: to use ...
23
votes
14answers
3k views

Do you know your 'KVZ's?

Concept In what ways can you scramble the English alphabet so that it can still be sung to the tune Twinkle Twinkle Little Star without ruining the tune? Rules Swapping Let's just assume the ...
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 ...
26
votes
11answers
4k views

Gambler's Fallacy Dice

The gambler's fallacy is a cognitive bias where we mistakenly expect things that have occurred often to be less likely to occur in the future and things that have not occurred in a while to be more ...
15
votes
11answers
1k views

Automatically anti-predictably assemble an alliterative aria

Thanks to @ComradeSparklePony for the title. This challenge should be very simple. You are given three lists. The first is a list of first names, in title case. The second is a list of adjectives, ...
15
votes
6answers
634 views

Generate a Pronounceable Nonsense Word \$n\$ syllables long

Your task is to generate a nonsense word that is reasonably pronounceable with the specified number of 'syllables'. Each time the program is run possibly results in a different nonsense word. ...
31
votes
49answers
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
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 ...
5
votes
18answers
1k views

To string or not to string

Given an input string, output at random the unique combinations with repetition of the characters in the input string, from length 1 up to the length of the input string, with an equal chance of each ...
18
votes
22answers
6k views

ssTTsSTtRrriinInnnnNNNIiinngg

Challenge For each character of the string except for the last one, do the following: Output the current character. Followed by randomly outputting from the following list a random number of times ...
11
votes
11answers
498 views

Generate a Baseball Pitch String

Goal Write a program or function that takes a positive integer n and randomly generate a legal series of pitches (henceforth called a Pitch string) of length ...
10
votes
8answers
577 views

Left Center Right (LCR) code golf

At a party, I was introduced to the game LCR. Now it's not a great game as there's no skill but only random chance. But it got me thinking, I could code this, and I made a quick program in R to model ...
58
votes
49answers
10k views

A game of dice, but avoid number 6 [closed]

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 ...
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 ...
8
votes
12answers
724 views

Simulate a Cisco Ping

Premise: For those in networking, you've most likely sent a ping to or from some device to make sure everything's properly connected. Cisco, a popular company in networking[citation needed], has a ...
10
votes
3answers
442 views

Arbitrary Randomness (Speed edition)

Given integer n, calculate a set of n random unique integers in range 1..n^2 (inclusive) ...
26
votes
24answers
3k views

Arbitrary Randomness

Randomness is fun. Challenges with no point are fun. Write a function that, given integer input n, will output a set (unordered, unique) of exactly ...
8
votes
3answers
275 views

Generate an RSA key pair

Given a positive integer \$N >= 4\$, output an RSA key pair (both the private and the public key) whose key length is \$N\$ bits. The RSA key generation algorithm is as follows: Choose an \$N\$-...
5
votes
29answers
1k views

Numbers Manipulation challenge

Use any programming language to generate two random digits between 1 and 9 (including both). Then your program should display: in the first line: the first random digit, in the second line: the ...
19
votes
7answers
2k views

Blind Random Sort

Here's a pretty common pattern for sorting algorithms: ...
18
votes
20answers
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 ...
9
votes
3answers
304 views

Shared Birthday Party

An office (let's call it "The Office") is going to cut down on wasted time in 2019 by consolidating office birthday parties. Any two people with a birthday between Monday and Friday (inclusive) of the ...
29
votes
69answers
8k views

Randomizing until 0

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

Draw a distribution diagram!

Challenge You are given three integers as input - min_value, max_value, sample_size, that you can pass to your answer as either array or several parameters. Your ...
13
votes
12answers
1k views

Fun with strings and numbers

Here's a programming puzzle for you: Given a list of pairs of strings and corresponding numbers, for example, [[A,37],[B,27],[C,21],[D,11],[E,10],[F,9],[G,3],[H,2]]...
31
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 ...
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-...
0
votes
0answers
133 views

Validate Sudoku (N by N) [duplicate]

Challenge : Create a random (pseudo random) Sudoku board with dimension n x n Input : Given : ...
19
votes
7answers
1k views

Rolling Quine Dice

Create a program that outputs itself. However, if the source code is repeated n times (meaning to concatenate a copy of the source code to the end n-1 times), then there should be 1/n probability ...
32
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 ...
11
votes
11answers
430 views

Drag Race Countdown

Challenge: In a hypothetical scenario, the countdown timer for a race has random intervals between the counts, to prevent premature starting, e.g. ...
7
votes
4answers
492 views

Bots playing a counting game

Introduction A childhood game designed to help children learn to count in french in Canadian schools is played as follows: Students go around the room counting up to 11 A number greater than 11 ...
9
votes
12answers
713 views

Asterisks viral

Given a positive integer N ("virality"), your program should create an ASCII-art drawing of a tree with two branches of length N extending downwards and/or rightwards from the top-left corner. The ...
23
votes
12answers
2k views

Drunkard's Journey Home

Drunkard's Journey Home In this challenge you are to write a program which simulates a drunkard stumbling his way home from the bar. Input: The input will be an adjacency matrix (representing a ...
18
votes
25answers
2k views

Factory workers

Challenge Factory workers are usually very hard-working. However, their work is now being commonly replaced with machines. You have to write a program that takes a number as input. It will print out ...
58
votes
118answers
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 ...
4
votes
4answers
340 views

Generate a heap of boxes

(The text asks how many boxes there are in the picture) Now you are required to generate such a problem and its answer. Input an integer n (optionally) random ...
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: ...
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 ...
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 ...
3
votes
1answer
272 views

Turn Your Program into a Snake! [duplicate]

...or "snakes but not too long". Inspired by this challenge and this comment. Task Write a program or a function that takes no input and outputs its own source code formatted as a snake according ...
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: ...