Skip to content

seeded random numbers? #109

@ianstormtaylor

Description

@ianstormtaylor

I love the Random helpers in this library, but I'm looking to use them for generative art, and I need a way to create seeded random numbers for consitent, repeatable outputs.

I was wondering if you'd be open to having an extra optional argument added to the functions. For example:

// from...
function bernoulli(p = 0.5) {}

// to...
function bernoulli(p = 0.5, random = Math.random) {}

So for example in p5.js you could do:

let r = Random.bernoulli(0.5, p.random)

Alternatively, the existing random helpers could be refactored to be a class that can be instantiated as well as used as static methods. So you could do:

let random = new Random(p.random)
let r = random.bernoulli()

Which might be nicer.

This would also make it easy to use libraries like seedrandom or seed-random too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions