Skip to content

Adding user defined random generator#22

Merged
BobAnkh merged 2 commits into
stack-rs:mainfrom
maxime-bruno:main
Jun 9, 2025
Merged

Adding user defined random generator#22
BobAnkh merged 2 commits into
stack-rs:mainfrom
maxime-bruno:main

Conversation

@maxime-bruno
Copy link
Copy Markdown
Contributor

Adds an option for the user to build NormalizedBw, SawtoothBw, NormalizedDelayPerPacket, and LogNormalizedDelayPerPacket with a custom random generator.

Description

StdRng which is the currently used random generator is not portable, meaning that on different architectures, or in the future, the randomly generated sequence could be different

I kept the default behavior, using StdRng, but added functions ending by _with_rng (build_with_rng for all and build_truncated_with_rng for normal laws) that let the user choose the random generator.

I modified the following types by making them parameterized (with StdRng as the default type):

  • NormalizedBw became NormalizedBw<Rng = StdRng>
  • SawtoothBw
  • NormalizedDelayPerPacket
  • LogNormalizedDelayPerPacket

I added the functions:

  • build_with_rng<Rng: RngCore + SeedableRng>(self) -> Self<Rng> for :
    • NormalizedBw
    • SawtoothBw
    • NormalizedDelayPerPacket
    • LogNormalizedDelayPerPacket
  • build_truncated_with_rng<Rng: RngCore + SeedableRng(mut self) -> Self<Rng> for:
    • NormalizedBw
    • NormalizedDelayPerPacket

I also added some documentation for the config of the models.

How Has This Been Tested

I tested (on Ubuntu 24.04) using the unit test and doc test included (I added several doc tests), and I'm open to adding additional ones.

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Documentation (non-breaking change which updates documentation)

Checklist

  • Code follows the code style of this project.
  • Changes follow the CONTRIBUTING guidelines.
  • Update necessary documentation accordingly.
  • Lint and tests pass locally with the changes.
  • Check issues and pull requests first. You don't want to duplicate effort.

Copy link
Copy Markdown
Member

@BobAnkh BobAnkh left a comment

Choose a reason for hiding this comment

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

LGTM

@BobAnkh BobAnkh merged commit d83af1d into stack-rs:main Jun 9, 2025
9 checks passed
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