Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rando
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tim Uruski
May 14, 2014
Programming
0
130
Rando
A lightning talk in which we learn a bit about Ruby by working with random values.
Tim Uruski
May 14, 2014
Tweet
Share
More Decks by Tim Uruski
See All by Tim Uruski
Exceptional Ruby
timuruski
0
99
Structure and Interpretation of Ruby Programs
timuruski
1
240
Rack and Middleware
timuruski
0
200
From Whence Rubygems - Mark 2
timuruski
0
150
The Waiting Game
timuruski
0
110
From Whence Rubygems
timuruski
1
95
Other Decks in Programming
See All in Programming
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
180
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
770
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.8k
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
160
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
560
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
2.6k
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
530
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
370
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
140
CSC307 Lecture 04
javiergs
PRO
0
650
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
390
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Docker and Python
trallard
47
3.7k
Raft: Consensus for Rubyists
vanstee
141
7.3k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
Measuring & Analyzing Core Web Vitals
bluesmoon
9
740
Claude Code のすすめ
schroneko
67
210k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
150
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
440
Darren the Foodie - Storyboard
khoart
PRO
2
2.3k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
630
Why Our Code Smells
bkeepers
PRO
340
58k
Transcript
Rando # Ruby v2.1.1 Random.srand 123 1
four random things 2
pick a random number between 100 and 200 3
(rand * 100 + 100).to_i => 169 4
(rand * 100 + 100).to_i => 169 NO! 5
rand(100..200) => 166 6
rand(*args) 7
how many kinds of random does Ruby have? 8
ObjectSpace .each_object .select { |obj| obj.respond_to?(:rand) } 9
Kernel Random #<Random:0x007fed39068820> 10
Kernel Random #<Random:0x007fed39068820> Random::DEFAULT => #<Random:0x007fed39068820> 11
Kernel Random #<Random:0x007fed39068820> 12
rand == Kernel.rand Random.rand == Random::DEFAULT.rand Kernel.rand != Random.rand 13
Kernel.rand => 0.6964691855978616 Random.rand => 0.6964691855978616 14
Kernel.rand(100) => 66 Random.rand(100) => 66 15
Kernel.rand(0..100) => 66 Random.rand(0..100) => 66 16
Kernel.rand(100.0) => 66 Random.rand(100.0) => 69.64691855978616 17
Kernel.rand(-100.0) => 66 Random.rand(-100.0) => ArgumentError 18
know your rand 19
generate a list of random numbers 20
(0..20).map { rand } => [0.696469, 0.286139, ...] 21
(0..20).map { rand } => [0.696469, 0.286139, ...] NO! 22
Array.new(20) { rand } => [0.696469, 0.286139, ...] 23
Array.new(*args) 24
Array.new(size, obj, &generator) 25
Array.new(3) => [nil, nil, nil] 26
Array.new(3, 0) => [0, 0, 0] 27
Array.new(3) { |n| n } => [0, 1, 2] 28
know your primitives 29
pick a random subset of elements from an array 30
users = %w[alice bob carol] subset = Array.new(2) { users[rand
* users.length] } => ['bob', 'alice'] 31
users = %w[alice bob carol] subset = Array.new(2) { users[rand
* users.length] } => ['bob', 'alice'] NO! 32
users = %w[alice bob carol] users.sample(2) => ['bob', 'carol'] 33
Array#sample(*args) 34
Array#sample(size, random: rng) 35
a = [1,2,3,4,5] a.sample => 3 36
a = [1,2,3,4,5] a.sample(3) => [3, 1, 5] 37
a = [1,2,3,4,5] a.sample(1) => [3] 38
a = [1,2,3,4,5] rng = Random.new(234) a.sample(random: rng) => 1
39
a = [1,2,3,4,5] rng = Random.new(234) a.sample(3, random: rng) =>
[1, 5, 2] 40
a = [1,2,3,4,5] rng = Random.new(234) a.shuffle(random: rng) => [3,
2, 5, 4, 1] 41
know your primitives (seriously) 42
generate a secure token from random values 43
token = '' 40.times do token << rand(0..255).to_s(16) end =>
'fe6d7e42dc62e6115...' 44
token = '' 40.times do token << rand(0..255).to_s(16) end =>
'fe6d7e42dc62e6115...' NO! 45
require 'securerandom' token = SecureRandom.hex(40) => '6011e8861f024cb75...' 46
require 'securerandom' token = SecureRandom.hex(40) => '6011e8861f024cb75...' => '8f90ea2187b50cb52...' =>
'cad2eb20a39939601...' => '272a822296de5b249...' => 'ad65839e646c27252...' 47
know your security (seriously) 48
hopefully you didn't learn anything 49