HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📌
hkob's Notion
/
ℹ️
逆引きFormula 2.0
/
💾
Database storage
/
🔢
一定時間ごとにページ順をランダムに並び替えるには?
🔢

一定時間ごとにページ順をランダムに並び替えるには?

Status
Update by 2.0
関数説明
📓
now
📓
timestamp
📓
floor
📓
id
📓
replaceAll
📓
toNumber
📓
*, multiply
📓
%, mod
属性名
1時間に1回入れ替え, 1分に1回入れ替え
返り値
Integer
関連するもの
ℹ️
逆引きFormula 2.0
に戻る
以前、以下の自学自習用小テストテンプレートを作ったときに問題を並び替える処理をしていました。その時の数式をここに記録していなかったので、覚書として記述しておきます。
自学自習用小テストテンプレート : Notion 解説 (57) - hkob's blog
Red Gregory さんの flashcards の実装に興味を持ちました。Show Answer のチェックを入れると、Description に書かれている一部分の文字が表示されるというものです。以前、Notion 座談会でトグルリストを使って、運転免許の勉強をした話題が出ていましたが、同じ系統のものです。 A short tutorial on how to create flashcards in @NotionHQ.
自学自習用小テストテンプレート : Notion 解説 (57) - hkob's blog
https://hkob.hatenablog.com/entry/2022/06/20/173000
自学自習用小テストテンプレート : Notion 解説 (57) - hkob's blog
やっている内容は現在時刻のタイムスタンプを3600秒でわり、その値とページの id ナンバーのうち数値のものだけを抽出した数字を掛け算しています。当初剰余を入れてなかったのですが、入れないと順番が入れ替わらないことに気づき、後から % 1000 を追加しました。下のものは1分で書き換えるようにはなっていますが、あくまでそのテーブルが描画されるときに値が変わるだけでリアルタイムに変わるわけではないことに注意してください。
  1. 1時間に1回入れ替え
    1. lets( /* 時間を 3600000 で割り小数点以下を切り捨てたものを変数 time_num に代入 */ time_num, (now().timestamp() / 3600000).floor(), /* id のうち数字以外のものを削除し、数値化したものを id_num に代入 */ id_num, id().replaceAll("[^\d]+", "").substring(0, 8).toNumber(), /* time_num と id_num の乗算結果を 1000 で割った余りを取得 */ (time_num * id_num) % 1000 )
      →
      📓
      now
      📓
      timestamp
      📓
      floor
      📓
      id
      📓
      replaceAll
      📓
      toNumber
      📓
      *, multiply
      📓
      %, mod
  1. 1分に1回入れ替え
    1. lets( /* 時間を 60000 で割り小数点以下を切り捨てたものを変数 time_num に代入 */ time_num, (now().timestamp() / 60000).floor(), /* id のうち数字以外のものを削除し、数値化したものを id_num に代入 */ id_num, id().replaceAll("[^\d]+", "").substring(0, 8).toNumber(), /* time_num と id_num の乗算結果を 1000 で割った余りを取得 */ (time_num * id_num) % 1000 )
      →
      📓
      now
      📓
      timestamp
      📓
      floor
      📓
      id
      📓
      replaceAll
      📓
      toNumber
      📓
      *, multiply
      📓
      %, mod
      名前
      1時間に1回書き換え
      1分に1回書き換え
      数式
      A
      B
      C
      D
      E
      F