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
Hello UUID
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
mimifuwacc
April 11, 2026
Technology
150
0
Share
Hello UUID
技術系サークル合同新歓2026 Day2
「Hello UUID」発表資料
mimifuwacc
April 11, 2026
More Decks by mimifuwacc
See All by mimifuwacc
RAID6 を楔形文字で組んで現代人を怖がらせましょう(実装編)
mimifuwacc
1
450
Other Decks in Technology
See All in Technology
LLM時代のリファクタリング戦略_AIエージェントによる段階的・安全なTS移行方法
play_inc
0
180
TypeScriptエンジニアのためのWASMランタイム入門:AssemblyScriptから理解するメモリの実態(ayano)
ayanoyuki
0
140
実践 TanStack Start ― 新規プロダクトを開発して確立した、サーバーとクライアント境界の設計パターン / Practical TanStack Start Server-Client Boundary Patterns
kaminashi
2
310
AIが変えた"品質の守り方"
kkakizaki
7
2.1k
業務に残された「良くない型」で考える「TypeScriptの難しさ」
sajikix
4
2k
キャリア25年目にしてTypeScript に出会うまで - 「型」を通じて振り返るプログラミング言語遍歴 / Meeting TypeScript After 25 Years in Tech - Looking Back at My Programming Language Journey Through "Types"
bitkey
PRO
2
280
Anthropic AIネイティブ・スタートアップ構築のプレイブック を理解する
nagatsu
0
180
TypeScriptで実現する既存APIを活用したリモートMCPサーバー構築 / TSKaigi 2026
soarteclab
1
280
A Harness for Behaviour: how to get AI to generate code that does what we intend, or "TDD in the age of AI"
xpmatteo
0
410
その英語学習、AWSで代替できませんか?
suzutatsu
1
240
[みん強]AIの価値を最大化するデータ基盤戦略:Self-Service型Data Meshへの転換とAgentic AI Meshに向けた取り組み with Snowflake他
y_matsubara
1
180
TSKaigi 2026 - 型プラグインシステムの実装に使われるテクニック
teamlab
PRO
2
420
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Color Theory Basics | Prateek | Gurzu
gurzu
0
310
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Accessibility Awareness
sabderemane
1
120
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
180
Facilitating Awesome Meetings
lara
57
6.9k
A Soul's Torment
seathinner
6
2.8k
sira's awesome portfolio website redesign presentation
elsirapls
0
250
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
790
Transcript
Hello UUID 技術系サークル合同新歓2026 Day2 id: mimifuwacc
自己紹介 みみ (id: mimifuwacc) - I 類 学部 4 年
コンピュータサイエンスプログラム - team411 / 工研 (幽霊?) など... - よく書く: TypeScript / Perl - 好き: ヰ世界情緒 / ラノベ / 超かぐや姫!/ Twitter / Linux … - 嫌い: Windows / Microsoft Office / TypeScript
UUID を配っています https://x.com/mimifuwacc/status/2036001613488496885
そもそも UUID って? - UUID (Universally Unique Identifier) とは, ソフトウェア上でオブジェクトを一意に識別する
識別子 - 128ビットの数値だが, 550e8400-e29b-41d4-a716-446655440000 のような表記もできる - 分散システム上での利用を考慮して設計されており,統制なしに作成しても 重複や偶然の一致が事実上おこらない ものとして使用可能 ref. https://ja.wikipedia.org/wiki/UUID
連番じゃダメ? - 分散環境で同時にデータを生成すると,番号が重複する可能性がある - 推測しやすい - c.g. 自分のユーザーIDが 100 なら,次の人は
101 だと簡単に推測できる - マージが大変 - c.g. A社のデータ (ID: 1〜100) と B社のデータ (ID: 1〜100) をマージすると,IDが ぶつかる
UUID なら... 統制なしに作成しても 重複や偶然の一致が事実上おこらないものとして使用可能!
UUIDv4 をつくってみる UUIDv4 の仕様 - 16バイト (128ビット) すべてランダム - 3ブロック目の先頭が「4」
(バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 500f295c-494b-4cf2-bc84-a3f081e13f7d
UUIDv4 をつくってみる UUIDv4 の仕様 - 16バイト (128ビット) すべてランダム - 3ブロック目の先頭が「4」
(バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 500f295c-494b-4cf2-bc84-a3f081e13f7d
UUIDv4 をつくってみる UUIDv4 の仕様 - 16バイト (128ビット) すべてランダム - 3ブロック目の先頭が「4」
(バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 500f295c-494b-4cf2-bc84-a3f081e13f7d
UUIDv4 をつくってみる - 実装する def uuidv4(): raw_bytes = bytearray(os.urandom(16)) raw_bytes[6]
= (raw_bytes[6] & 0x0F) | 0x40 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}"
UUIDv4 をつくってみる - 実装する def uuidv4(): raw_bytes = bytearray(os.urandom(16)) raw_bytes[6]
= (raw_bytes[6] & 0x0F) | 0x40 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" 予測不可能な乱数を生成 ref. https://docs.python.org/ja/3/library/os.html#os.urandom
UUIDv4 をつくってみる - 実装する def uuidv4(): raw_bytes = bytearray(os.urandom(16)) raw_bytes[6]
= (raw_bytes[6] & 0x0F) | 0x40 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" 0000 1111 0100 0000
UUIDv4 をつくってみる - 実装する def uuidv4(): raw_bytes = bytearray(os.urandom(16)) raw_bytes[6]
= (raw_bytes[6] & 0x0F) | 0x40 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" 0011 1111 1000 0000
UUIDv4 をつくってみる - 実装する def uuidv4(): raw_bytes = bytearray(os.urandom(16)) raw_bytes[6]
= (raw_bytes[6] & 0x0F) | 0x40 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}"
UUIDv7 をつくってみる UUIDv7 の仕様 - 先頭6バイト (48ビット) にミリ秒精度のタイムスタンプを格納 → 時間順でソートが可能!
- それ以外はランダム - 3ブロック目の先頭が「7」 (バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 019d78e6-82f7-73df-8182-5a9dbbe7f5c4
UUIDv7 をつくってみる UUIDv7 の仕様 - 先頭6バイト (48ビット) にミリ秒精度のタイムスタンプを格納 → 時間順でソートが可能!
- それ以外はランダム - 3ブロック目の先頭が「7」 (バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 019d78e6-82f7-73df-8182-5a9dbbe7f5c4
UUIDv7 をつくってみる UUIDv7 の仕様 - 先頭6バイト (48ビット) にミリ秒精度のタイムスタンプを格納 → 時間順でソートが可能!
- それ以外はランダム - 3ブロック目の先頭が「7」 (バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 019d78e6-82f7-73df-8182-5a9dbbe7f5c4
UUIDv7 をつくってみる UUIDv7 の仕様 - 先頭6バイト (48ビット) にミリ秒精度のタイムスタンプを格納 → 時間順でソートが可能!
- それ以外はランダム - 3ブロック目の先頭が「7」 (バージョン番号) - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9, a, b のどれか) 019d78e6-82f7-73df-8182-5a9dbbe7f5c4
UUIDv7 をつくってみる - 実装する def uuidv7(): timestamp_ms = int(time.time_ns() /
1_000_000) random_bytes = bytearray(os.urandom(10)) raw_bytes = bytearray(timestamp_ms.to_bytes(6, "big")) raw_bytes.extend(random_bytes) raw_bytes[6] = (raw_bytes[6] & 0x0F) | 0x70 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}"
UUIDv7 をつくってみる - 実装する def uuidv7(): timestamp_ms = time.time_ns() //
1_000_000 random_bytes = bytearray(os.urandom(10)) raw_bytes = bytearray(timestamp_ms.to_bytes(6, "big")) raw_bytes.extend(random_bytes) raw_bytes[6] = (raw_bytes[6] & 0x0F) | 0x70 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" ミリ秒単位で現在時刻を取得
UUIDv7 をつくってみる - 実装する def uuidv7(): timestamp_ms = time.time_ns() //
1_000_000 random_bytes = bytearray(os.urandom(10)) raw_bytes = bytearray(timestamp_ms.to_bytes(6, "big")) raw_bytes.extend(random_bytes) raw_bytes[6] = (raw_bytes[6] & 0x0F) | 0x70 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" 6バイトにする
UUIDv7 をつくってみる - 実装する def uuidv7(): timestamp_ms = time.time_ns() //
1_000_000 random_bytes = bytearray(os.urandom(10)) raw_bytes = bytearray(timestamp_ms.to_bytes(6, "big")) raw_bytes.extend(random_bytes) raw_bytes[6] = (raw_bytes[6] & 0x0F) | 0x70 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" 0000 1111 0111 0000
UUIDv7 をつくってみる - 実装する def uuidv7(): timestamp_ms = time.time_ns() //
1_000_000 random_bytes = bytearray(os.urandom(10)) raw_bytes = bytearray(timestamp_ms.to_bytes(6, "big")) raw_bytes.extend(random_bytes) raw_bytes[6] = (raw_bytes[6] & 0x0F) | 0x70 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}" 0011 1111 1000 0000
UUIDv7 をつくってみる - 実装する def uuidv7(): timestamp_ms = time.time_ns() //
1_000_000 random_bytes = bytearray(os.urandom(10)) raw_bytes = bytearray(timestamp_ms.to_bytes(6, "big")) raw_bytes.extend(random_bytes) raw_bytes[6] = (raw_bytes[6] & 0x0F) | 0x70 raw_bytes[8] = (raw_bytes[8] & 0x3F) | 0x80 h = raw_bytes.hex() return f"{h[0:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:32]}"
覚えておくと便利(?) UUID の仕様 - 3ブロック目の先頭がバージョン番号 - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9,
a, b のどれか) 500f295c-494b-4cf2-bc84-a3f081e13f7d
UUIDv4 あげますよ
8373406a-0b4d-3ff8 -c5cc-c546bccbfd85
8373406a-0b4d-3ff8 -c5cc-c546bccbfd85 v4 なのに「4」じゃない!
8373406a-0b4d-3ff8 -c5cc-c546bccbfd85 v4 なのに「4」じゃない! 「8, 9, a ,b」じゃない!
8373406a-0b4d-3ff8 -c5cc-c546bccbfd85 v4 なのに「4」じゃない! 「8, 9, a ,b」じゃない! 偽物だ!!
覚えておくと便利(?) UUID の仕様 - 3ブロック目の先頭がバージョン番号 - 4ブロック目が「0b10」で始まる (4ブロック目の先頭が 8, 9,
a, b のどれか) 500f295c-494b-4cf2-bc84-a3f081e13f7d
ありがとうございました! - repo: https://github.com/mimifuwacc/uuidgen-py uvx git+https://github.com/mimifuwacc/uuidgen-py id: mimifuwacc Twitter: https://twitter.com/mimifuwacc
- 注意! 実用するときはライブラリを使おう - 手書き UUID をプレゼントします!