Skip to content

RandomDistributions: explicit parameters for of::random::uniform#7686

Merged
ofTheo merged 1 commit intoopenframeworks:masterfrom
artificiel:random-explicit-parameters
Sep 28, 2023
Merged

RandomDistributions: explicit parameters for of::random::uniform#7686
ofTheo merged 1 commit intoopenframeworks:masterfrom
artificiel:random-explicit-parameters

Conversation

@artificiel
Copy link
Copy Markdown
Contributor

@artificiel artificiel commented Sep 28, 2023

of::random::uniform was exercising perfect forwarding to move arguments into the actual distributions, however this created some ambiguities with zero or one parameters — technically the underlying distribution requires min and max and somehow forwarding nothing satisfied the criteria.

so reverted to explicit T min T max params, with the option of having a single (max) param, which defaults to 1.0 in the case of float — so no implicit "range" for int versions. so:

of::random::uniform(); // returns float (0,1]
of::random::uniform(5.0); // returns float (0,5]
of::random::uniform<int>(5); // returns int (0,5)
of::random::unfiorm<int>(); // does not compile

[edit to add: this does not affect the backward-compatibility of ofRandom() which already wraps explicit parameters]

@ofTheo ofTheo merged commit f9f6444 into openframeworks:master Sep 28, 2023
@artificiel artificiel deleted the random-explicit-parameters branch September 28, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants