Coder Social home page Coder Social logo

cpprandom's People

Contributors

athas avatar spaarmann avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpprandom's Issues

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

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.

uniform_int_distribution i64 minstd_rand generates outside range

uniform_int_distribution i64 minstd_rand generates numbers outside the range when the range is between negative numbers.

import "lib/github.com/diku-dk/cpprandom/random"
module dist = uniform_int_distribution i64 minstd_rand
let snd (_,b) = b
let main = snd <| dist.rand (-20,-10) (minstd_rand.rng_from_seed [1234])

This program returns 4294967281i64, for example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.