Skip to content

Add Random instance for Natural #44

Description

@ndmitchell

With GHC 8.2 there is Natural in the base library, so it would be good if Random provided a suitable instance.

Activity

  1. cartazio commented on Oct 17, 2017

    @cartazio
    Contributor
  2. ndmitchell commented on Oct 17, 2017

    @ndmitchell
    Author

    If you don't do what you do for Integer it would be massively confusing. And for Integer you use maxBound :: Int - which seems at least consistent.

  3. treeowl commented on Feb 18, 2019

    @treeowl

    @ndmitchell using maxBound :: Int sounds extremely wrong. I would expect something with more of a Gaussian-style shape with a fairly large standard deviation for Integer, and probably half of that for Natural.

  4. ndmitchell commented on Feb 18, 2019

    @ndmitchell
    Author

    @treeowl perhaps, all I'm saying is they should be consistent. I would like the random Integer to never overflow all my memory though, so it needs a limit of some kind.

  5. treeowl commented on Feb 18, 2019

    @treeowl

    Ah, I suppose it does, for such practical reasons. But maxBound :: Int seems way too small. If the standard deviation is something like maxInt ^ n for some small n (to pick something pretty arbitrary), then you could cut off at some sensible multiple of that without losing much. What I really don't know is whether there is a good principled choice of distribution.

  6. cartazio commented on Feb 18, 2019

    @cartazio
    Contributor
  7. cartazio commented on Feb 19, 2019

    @cartazio
    Contributor
  8. lehins commented on Jun 23, 2020

    @lehins
    Contributor

    There is a new instance UniformRange Natural. I don't know if adding instance Random Natural is a good idea. The broken instance for Integer is already there, so we'll keep it for backwards compatibility, but adding new broken instances doesn't feel right. In any case Natural can now be generated with uniformR and uniformRM

  9. added this to the 1.2.0 milestone on Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions