Skip to content

6桁の番号で部屋を割り出せるようにする#40

Merged
rokuosan merged 8 commits intodevelopfrom
add-six-numbers
Feb 21, 2026
Merged

6桁の番号で部屋を割り出せるようにする#40
rokuosan merged 8 commits intodevelopfrom
add-six-numbers

Conversation

@rokuosan
Copy link
Contributor

@rokuosan rokuosan commented Feb 21, 2026

関連 Pull Request / Issue

  • 関連する Pull Request や Issue があればリンクを貼りましょう

問題点 / やりたいこと / 解決したいこと / 背景 など

部屋を割り出すときに、QRコード以外の方法が必要だったので6桁の数字を導入することにした。
この6桁の番号から部屋番号を割り出せるようにしたい。

期待すること(状態や動作など)

  • ここに期待することを書きましょう

やったこと

  • KV を追加する
  • 6桁の数字を生成する君を作る
  • shortcode から room を取得できる

Snowflake ←→ 6桁の番号 の対応を KV に10分間だけ保持するようにした。
この10分という数字は Durable Object が消える時間と同じにしている。

重複が起きた場合はリトライして新しい番号を生成する。

確認手順

ここに確認手順を書きましょう

@rokuosan rokuosan requested a review from taiseiue February 21, 2026 20:33
Copy link
Contributor

@taiseiue taiseiue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よさそうです

const max = 999999;
return Math.floor(Math.random() * (max - min + 1) + min).toString();
return Math.floor(
(crypto.getRandomValues(new Uint32Array(1))[0] / (0xffffffff + 1)) * (max - min + 1) + min,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[メモ] 0.0 ≤ x < 1.0の数字を生成している

@rokuosan
Copy link
Contributor Author

:dmdm:

@rokuosan rokuosan merged commit 7662391 into develop Feb 21, 2026
1 check passed
@rokuosan rokuosan deleted the add-six-numbers branch February 21, 2026 20:42
@rokuosan rokuosan self-assigned this Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants