Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

  • Add randstr-secure-random? parameter in config.rkt to enable/disable cryptographically secure random
  • Create randstr-random helper function in config.rkt that uses crypto-random-bytes when secure mode is on
  • Update char-classes.rkt to use the new randstr-random function
  • Update generator.rkt to use the new randstr-random function
  • Add CLI option -s/--secure to enable secure random mode
  • Add tests for secure random functionality
  • Update documentation (README.md, CHANGELOG.md, Scribble docs)
  • Address code review feedback:
    • Replace magic numbers with named constants (2^64, BITS-PER-BYTE, VALUES-PER-BYTE, MIN-BYTES)
    • Implement rejection sampling for unbiased crypto random integers
    • Extract byte count calculation into helper function bytes-needed-for
    • Add inexact->exact to ensure bytes-needed-for returns exact integer
    • Add comment clarifying big-endian byte order in integer conversion
Original prompt

增加一个选项提供密码学安全的随机数发生器


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 12, 2026 13:25
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option for cryptographic secure random number generator Add cryptographically secure random number generator option Jan 12, 2026
Copilot AI requested a review from hugefiver January 12, 2026 13:31
@hugefiver hugefiver marked this pull request as ready for review January 12, 2026 15:41
Copilot AI review requested due to automatic review settings January 12, 2026 15:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

;; Calculate the number of bytes needed to represent values up to n
;; Uses ceiling to ensure we have enough bytes for the full range
(define (bytes-needed-for n)
(max MIN-BYTES (ceiling (/ (+ 1 (integer-length n)) BITS-PER-BYTE))))
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The function bytes-needed-for uses ceiling which returns an inexact number when the input is inexact. However, the result needs to be an exact integer for use in crypto-random-bytes. This could cause a contract violation if (integer-length n) or the division produces an inexact result.

Consider using inexact->exact after ceiling or ensuring the entire calculation uses exact arithmetic:

(max MIN-BYTES (inexact->exact (ceiling (/ (+ 1 (integer-length n)) BITS-PER-BYTE))))
Suggested change
(max MIN-BYTES (ceiling (/ (+ 1 (integer-length n)) BITS-PER-BYTE))))
(max MIN-BYTES (inexact->exact (ceiling (/ (+ 1 (integer-length n)) BITS-PER-BYTE)))))

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied in commit 64b605a. Added inexact->exact wrapper to ensure the function returns an exact integer for crypto-random-bytes.

Comment on lines +55 to +56
[val (for/fold ([acc 0]) ([i (in-range byte-count)])
(+ (bytes-ref bytes i) (* acc VALUES-PER-BYTE)))])
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The byte-to-integer conversion accumulates bytes in little-endian order (least significant byte first), but the comment doesn't clarify this. The order doesn't affect randomness, but for code clarity and potential debugging, consider adding a comment about the byte order being used, or using a more explicit loop structure that makes the order clear.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied in commit 64b605a. Added comment clarifying big-endian byte order in the conversion.

@hugefiver
Copy link
Owner

@copilot apply changes based on the comments in this thread

Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 12, 2026

@copilot apply changes based on the comments in this thread

Done. Applied both changes from the review in commit 64b605a.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@hugefiver hugefiver merged commit 4162ce3 into master Jan 13, 2026
7 checks passed
@hugefiver hugefiver deleted the copilot/add-secure-random-number-generator branch January 13, 2026 05:04
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