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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
100
Structure and Interpretation of Ruby Programs
timuruski
1
250
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
100
Other Decks in Programming
See All in Programming
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
170
モダンOBSプラグイン開発
umireon
0
160
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
410
CSC307 Lecture 14
javiergs
PRO
0
480
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
190
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
1.1k
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
570
存在論的プログラミング: 時間と存在を記述する
koriym
3
210
Angular-Apps smarter machen mit Gen AI: Lokal und offlinefähig - Hands-on Workshop!
christianliebel
PRO
0
130
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.3k
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
270
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
280
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
Code Review Best Practice
trishagee
74
20k
Leo the Paperboy
mayatellez
4
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
110
The SEO Collaboration Effect
kristinabergwall1
0
400
Automating Front-end Workflow
addyosmani
1370
200k
Between Models and Reality
mayunak
2
240
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
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