Hot answers tagged


C It's important to decide who is buying as quickly as possible, so as not to waste precious drinking time - hence C is the obvious choice in order to get maximum performance: #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { const char *buyer; int n; srand(time(NULL)); // make sure we get a good random ...


PHP Couldn't let this go, so here is another one: $f = fopen('/dev/random','r'); $s = fread($f, 4); fclose($f); $names = ['John', 'Jeff', 'Emma', 'Steve', 'Julie']; echo $names[$s % count($names)];


WinDbg, 1 byte # Wow! Never expected a 1 byte solution from WinDbg! # searches for a disassembly pattern, but since there's no parameters, it looks to just return the next assembly instruction in whatever dump/process you're attached to. Not sure the logic for setting the initial address, but it does. Sample output: 0:000> # Search address set to ...


Minecraft 1.12 Redstone Command Blocks, 4,355 2,872 bytes (Size determined by saved structure block file size.) Here is a full YouTube overview, but I'll try to outline the code below. Setup Routine: This sets up the 40x40 grid of Minecraft armor stands. Armor stands are necessary because Minecraft has no way to substitute variables into world coordinates. ...


Haskell It's too transparent if it always returns the same name so try the following import Control.Monad import System.Exit import Control.Concurrent import Control.Concurrent.MVar data Person = John | Jeff | Emma | Steve | Julie deriving (Show, Enum) next Julie = John next p = succ p rotate :: MVar Person -> IO () rotate mp = modifyMVar_ mp (return ...


Bash - maximum simplicity A very simple example - let's avoid any problems by doing it the textbook way. Don't forget to seed the generator from the system clock for a good result! #!/bin/bash names=(John Jeff Emma Steve Julie) # Create an array with the list of names RANDOM=$SECONDS # Seed the random generator with seconds since ...


Java 7, 33 30 27 bytes int a(){return hashCode();} Because Java.


MATLAB, 3 bytes why why provides answers to almost any question. A few examples: why The programmer suggested it. why To fool the tall good and smart system manager. why You insisted on it. why How should I know? This is shorter than any rand function I can think of.


C# using System; using System.Linq; namespace PCCG { class PCCG31836 { public static void Main() { var names = new string[]{ "John", "Jeff", "Emma", "Steve", "Julie" }; var rng = new Random(); names.OrderBy(name => rng.Next()); Console.WriteLine(names[0]); } } }


JavaScript (ES6), 25 ":)".repeat(new Date%256) Outputs (REPL): > ":)".repeat(new Date%256) ":):):):):)" > ":)".repeat(new Date%256) ":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):...


Minecraft, 358 293 277 276 bytes Implementing Minceraft in Minecraft Should be run as a set of commands in game. Should be run on a fresh superflat (redstone ready) world. Byte count is the amount of characters you need to type, including newlines. /scoreboard objectives add s dummy /summon bat /execute as @e[type=bat] store result score o s run data get ...


Operation Flashpoint scripting language, 48 bytes f={s="duck\n";s+([s,""]select random 1)+"goose"} Always prints either one or two ducks. random 1 returns a (floating point) number between 0 and 1. That number is passed as an argument to select along with the array [s,""]. The random number is then rounded to the nearest integer (either 0 or 1), and the ...


PowerShell $names = @{0='John'; 1='Jeff'; 2='Emma'; 3='Steve'; 4='Julie'} $id = random -maximum $names.Length $names[$id] This will always output John.


Q show rand `John`Jeff`Emma`Steve`Julie; exit 0;


R, 1 byte t Outputs the function's source code and a memory pointer address which changes with every (re-)start of R.


huh?, 0 bytes An empty program still produces output. The last lines of the Python interpreter that are executed: print "..." f = open('Notes.txt', 'w') f.write(time.strftime("%c") + " - The user tried to give me commands again. I still have no idea what they are talking about...\n") At the end of a program, the Python ...


J (4 bytes) Couldn't resist. ?~10 In J, if F is dyadic , F~ x is the same as x F x.


Pyth, 8 u+G!OTsQ Try it online This uses Pyth's second mode on reduce, that looks for repeated input then exits. Explanation u+G!OTsQ ## Implicit: Q=eval(input()) u sQ ## reduce with 2 arguments, which causes a loop until the reduce gets the ## same argument twice +G ## lambda G,H: G + ... !OT ## boolean not of random ...


Wolfram Language (Mathematica), 20 bytes RandomPoint@Sphere[] Try it online! Does exactly what it says on the tin.


World of Warcraft 81 Bytes Here's a macro that you can run in World of Warcraft. /run for x=1,random(1,9) do SendChatMessage("Duck") end; SendChatMessage("Goose")


Minecraft <1.13, 72 54 bytes Sorry, I had to. Instructions: Create a new Minecraft world in Creative Mode Find the save folder for that world, and place the following code in data/functions/minecraft/ddg.mcfunction Run /function ddg in the game console How it works: Outputs the word "duck" for every entity in the world, then outputs the word "goose". ...


x86 Machine Code (for Intel Ivy Bridge and later), 17 bytes 31 C9 0F C7 F0 31 D2 F7 F6 42 01 D1 39 F2 74 F2 C3 The above bytes of code define a function that simulates an exploding die. It takes a single input, passed in the ESI register, indicating the maximum number of the die. It returns a single value in the ECX register, which is the result of the ...


Perl use strict; my @people = qw/John Jeff Emma Steve Julie/; my @index = int(rand() * 5); print "Person @index is buying: $people[@index]\n";


Operation Flashpoint scripting language, 643 624 bytes f={l=["""","!","#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\","]","^","_","`","a","b","c","d","e","f","g","h",...


Baby Language, 0 bytes Try it online! I knew this could be fun with a non-deterministic tarpit! I looked through the category on the Esolang wiki and found this language... From the page: A Baby Language interpreter ignores the input program and does something random. (Likewise, a Baby Language compiler generates a random executable.) As such, whatever you ...


C - 116 (including artistic whitespace) x,i; main (){ srand (time (0)); for (x= rand() %256; i<x; i++) printf(":)");} I never get to do ASCII art code, and the 65 needed characters in the code are already running long as is... This was actually harder than I ...


Shell Reads a single sample from the microphone stream and prints its least-significant bit, which should be dominated by noise. EDIT: Changed to unmute the microphone ... and everything else too! # Warning - unmutes EVERYTHING! for DEV in `amixer | grep Simple | sed -e "s/.*'\(.*\)'.*/\\1/" -e "s/ /~/g"` do amixer -q -- sset "`...


Labyrinth, 5 bytes v ! @ Either prints 0 or nothing (50% chance each). Try it online! There is a very specific case in which Labyrinth exhibits random behaviour: There must be a wall in front of the instruction pointer and behind it. There must be a non-wall left and right of the instruction pointer. The current top of the stack must be zero. If all of ...


Minecraft, 5 4 bytes op 8 Used by typing into a server's console or a command block and giving it power. Can be run from the chat interface by prepending a /. Usually this does nothing, but if there's a player with the username "8" on the server, they will be given operator permissions. Note that while Minecraft normally requires usernames to be 3 ...


GolfScript, 12 characters ":)"256rand* Nothing really interesting here.

Only top voted, non community-wiki answers of a minimum length are eligible