Upgrade to Pro — share decks privately, control downloads, hide ads and more …

lol im so random!

lol im so random!

Presented at !!con (http://bangbangcon.com) 2016

Randomness has many applications in computing ranging from cryptography and statistics to generative art and simulation, but where does randomness come from? When you ask for a random number from your system, how truly random is it?

This talk will explore randomness in software practice in a variety of contexts. Touching on sources of entropy, pseudo-random number generation, and what it means to be cryptographically secure, this talk will explore both the algorithms and the APIs that supply us with random numbers. This talk will also cover the mechanisms for testing and verifying statistical randomness. Interspersed seemingly randomly throughout will be some great examples of bots, games, and generative art that use randomness and procedural generation in creative and unusual ways. You will come away from this high-level overview with a newfound sense of respect and awe for the humble Math.random().

https://mobile.twitter.com/markwunsch/timelines/729376400218701824

Mark Wunsch

May 08, 2016
Tweet

More Decks by Mark Wunsch

Other Decks in Technology

Transcript

  1. John von Neumann Various Techniques Used in Connection With Random

    Digits “Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin. For, as has been pointed out several times, there is no such thing as a random number — there are only methods to produce random numbers, and a strict arithmetic procedure of course is not such a method.”
  2. (defn rand “Returns a random floating point number between 0

    (inclusive) and n (default 1) (exclusive).” ([] (. Math (random))) ([n] (* n (rand)))) clojure.core
  3. public static double random() Returns a double value with a

    positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range. When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression new java.util.Random() This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else. java.lang.Math
  4. Mary Rose Cook A practical introduction to functional programming https://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming

    “Functional code is characterized by one thing: the absence of side effects. It doesn’t rely on data outside the current function, and it doesn’t change data that exists outside the current function.”
  5. > import System.Random > random (mkStdGen 42) :: (Int, StdGen)

    (-3900021226967401631,2060101257 2103410263)
  6. Property-Based Testing QuickCheck & its scions
 http://www.cse.chalmers.se/~rjmh/QuickCheck/ Gary Fredericks —

    Purely Random
 from Clojure/West 2015
 https://www.youtube.com/watch?v=u0t-6lUvXHo
  7. “PRNGs are currently implemented as a modified Mersenne Twister with

    a period of 2**19937-1” 
 http://ruby-doc.org/core-2.2.2/Random.html “Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1.” 
 https://docs.python.org/3/library/random.html “Random number generation in Julia uses the Mersenne Twister library via MersenneTwister objects.” 
 http://docs.julialang.org/en/release-0.4/stdlib/numbers#random-numbers
  8. TIFU by using Math.random()
 https://medium.com/@betable/tifu-by-using-math-random-f1c308c4fd9d There’s Math.random(), and then there’s

    Math.random()
 http://v8project.blogspot.com/2015/12/theres-mathrandom-and-then-theres.html
  9. 101262 024567 163231 107002 047500 141110 112373 100363 141204 177347

    033443 153461 150705 005261 075113 041430 057531 072242 066770 001374 110052 004716 160523 064356 127045 113127 072433 031735 146001 040647 105205 104464 010021 174056 072621 047566 041173 074062 063702 142662 012703 064566 004331 124752 002455 051065 171176 014151 024462 007765 036437 057554 111072 070733 014741 102411 117460 057656 073073 127016 124774 015743 013005 153673 171613 152444 166643 141710 150477 054502 150175 055630 045701 024774 074654 021546 164660 127465 075035 027547 032112 110437 170726 052324 112261 011234 163423 053520 042643 123732 016343 143734 003171 047752 161731 104761 106311 014712 162121 020272 150470 046124 156427 104625 172660 135352 034330 164771 076535 031660 146333 030455 041511 072500 017333 102715 074317 065237 075131 054032 001217 044045 046220 073062 021534 060345 065446 034237 130226 034734 061603 022274 133362 066144 103771 055055 073664 162725 013732 123243 144705 061310 106532 161743 002362 002610 111577 071633 124030 024525 146333 101235 160420 030052 002761 175720 125564 017030 007503 120511 124152 032335 041561 057646 177455 030002 010667 074013
  10. $ expr $RANDOM % 6 + 1 $ awk ‘BEGIN

    { srand(); print 1 + int(rand() * 6); }’ $ cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("0,2,4,5,7,9,11,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | aplay -c 2 -f S32_LE -r 16000 http://blog.robertelder.org/bash-one-liner-compose-music/
  11. ^D