Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Tasks involving random numbers and/or output.
1
vote
Pick a random number between 0 and n using a constant source of randomness
Go, 63 61 bytes
import."math/rand"
var n=0;func R(){q:=n;for;q<n+1;n=Int(){}}
Use it like this:
func main() {
n = 5000
R()
print(n)
}
Test it live at the go playground
2
votes
Death By Shock Probe: That's a lot of dice
Go, 87 bytes
Naive solution
import"math/rand";func r(){o,n:=0,2<<19;for i:=0;i<n;i++{o+=rand.Intn(4)};println(o+n)}
Run online here: http://play.golang.org/p/gwP5Os7_Sq
Due to the way the Go play …
2
votes
Death By Shock Probe: That's a lot of dice
Go, 78 bytes
Golfed
import."math/rand";func r()(o int){for i:=2<<19;i>=0;i--{o+=Intn(4)+1};return}
Still working on it
Run online here http://play.golang.org/p/pCliUpu9Eq
0
votes
Monte Carlo estimator of Pi
Run it here: http://play.golang.org/p/F5YniIncor
Please note that random on play.golang.org cannot be seeded by time (since the date is always the same) so you need to change the seed manually.
1e6 is …
10
votes
Random script that isn't actually random
Javascript (with Underscore.js)
Since javascript does not have a built in shuffle we'll be using Underscore.js
var people = ['John', 'Jeff', 'Emma', 'Steve', 'Julie'];
_.shuffle(people); // Shuffle …