uniform_int_distribution misbehaves if the range exceeds the range of the underlying rng_engine

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Domain
backend

Research direction

Start at lib/github.com/diku-dk/cpprandom/random.fut lines 486-487, focusing on the loop that computes secure_max for uniform_int_distribution. Reproduce the supplied program and confirm that the distribution terminates when the requested range exceeds the underlying rng range, without leaving the distribution unbalanced.

Written by the indexing model from the issue text.

Description

bug hacktoberfest

For example, this program will not terminate:

import "lib/github.com/diku-dk/cpprandom/random"

module rng = minstd_rand
module dist = uniform_int_distribution u32 rng

let main (seed: i32) =
  let r = rng.rng_from_seed [seed]
  in dist.rand (rng.min,rng.max+1) r

The problem is this loop where it tries to ensure that the distribution is not unbalanced. If the range is too great, then secure_max becomes 0, and the loop becomes infinite.

Dominant language
Futhark
Stars
4
Forks
3
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.