Skip to content

Use Abseil Random library#118

Open
copybara-service[bot] wants to merge 1 commit intomainfrom
copybara/899501716
Open

Use Abseil Random library#118
copybara-service[bot] wants to merge 1 commit intomainfrom
copybara/899501716

Conversation

@copybara-service
Copy link
Copy Markdown

Use Abseil Random library

https://abseil.io/docs/cpp/guides/random

Replace legacy C random functions (srand/rand) and time-based seeding
with absl::BitGenRef and absl::Uniform. This provides better randomness
properties and removes dependencies on global state.

  • RandGen & RandEquivalent: Update signatures to accept an
    absl::BitGenRef or an optional seed (std::optional<uint64_t>).
    When a seed is provided, it is used to initialize an internal bit
    generator.
  • ArcSelector: Update the operator() interface to require an
    absl::BitGenRef. This ensures that arc selection is driven by the
    caller's random source.
  • WeightGenerator: Standardize weight generation templates (e.g.,
    WeightGenerate<T>) to take a bit generator. This allows for
    reproducible random weights in tests and FST generation.
  • pywrapfst: Change randgen and randequivalent to default to
    non-deterministic seeding (seed=None) instead of time-based seeding.

https://abseil.io/docs/cpp/guides/random

Replace legacy C random functions (srand/rand) and time-based seeding
with absl::BitGenRef and absl::Uniform. This provides better randomness
properties and removes dependencies on global state.

* **RandGen & RandEquivalent:** Update signatures to accept an
  `absl::BitGenRef` or an optional seed (`std::optional<uint64_t>`).
  When a seed is provided, it is used to initialize an internal bit
  generator.
* **ArcSelector:** Update the `operator()` interface to require an
  `absl::BitGenRef`. This ensures that arc selection is driven by the
  caller's random source.
* **WeightGenerator:** Standardize weight generation templates (e.g.,
  `WeightGenerate<T>`) to take a bit generator. This allows for
  reproducible random weights in tests and FST generation.
* **pywrapfst:** Change `randgen` and `randequivalent` to default to
  non-deterministic seeding (`seed=None`) instead of time-based seeding.

PiperOrigin-RevId: 899501716
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant