Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lib/lulucat/fsrs_card.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,13 @@ defmodule Fsrs.Card do
# Private functions

defp generate_card_id do
# Epoch milliseconds of when the card was created.
# 创建卡片时的 epoch 毫秒时间戳。
card_id = System.system_time(:millisecond)

# Wait 1 ms to prevent potential card_id collision on next card creation.
# 等待 1 毫秒,防止下一次创建卡片时发生 card_id 冲突。
Process.sleep(1)

card_id
# Use nanosecond timestamp combined with a random component for unique IDs.
# This avoids Process.sleep(1) bottleneck while maintaining uniqueness.
# 使用纳秒时间戳结合随机组件生成唯一ID,避免 Process.sleep(1) 的性能瓶颈。
timestamp = System.system_time(:nanosecond)
random_component = :rand.uniform(1000)

Bitwise.bxor(timestamp, random_component)
end

defp handle_step(step, state) do
Expand Down