Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils): add random module #267

Merged
merged 3 commits into from
Oct 20, 2021
Merged

feat(utils): add random module #267

merged 3 commits into from
Oct 20, 2021

Conversation

elenaf9
Copy link
Contributor

@elenaf9 elenaf9 commented Oct 7, 2021

Description of change

Extract random methods into a single module stronghold_utils::random.
Ensure that random::bytestring() and random::string() are never empty.

Type of change

  • Enhancement (a non-breaking change which adds functionality)

Change checklist

Add an x to the boxes that are relevant to your changes, and delete any items that are not.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes


// Random Bytestring with random length in range 1..4096.
pub fn bytestring() -> Vec<u8> {
let s = (random::<usize>() % 4095) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better move magic constant outside, or make the function call configurable in terms of range.

Copy link
Contributor

@felsweg-iota felsweg-iota left a comment

Choose a reason for hiding this comment

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

looks good to me

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