Fix: Always return false when likelihood is zero#315
Merged
FlorianKoerner merged 1 commit intodicebear:mainfrom May 14, 2023
Merged
Fix: Always return false when likelihood is zero#315FlorianKoerner merged 1 commit intodicebear:mainfrom
FlorianKoerner merged 1 commit intodicebear:mainfrom
Conversation
Member
|
Thanks for the fix :) |
Member
|
Because this fix changes the output of multiple avatars, it will not be released until the next major release. As a small workaround, you could also set the corresponding option to an empty array. Here is an example: JS-Library import { createAvatar } from '@dicebear/core';
import { adventurer } from '@dicebear/collection';
const avatar = createAvatar(adventurer, {
"features": [],
"featuresProbability": 0
});
const svg = avatar.toString();HTTP-API CLI |
FlorianKoerner
added a commit
that referenced
this pull request
May 18, 2023
This reverts commit 598b7af.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed that sometimes, even when the probability of an option was zero, it would show up from time to time.
The bug was coming from
prng.bool(), sinceinteger(0, 100)would return a random value including 0 or 100. This means that even when the likelihood was 0, there was a 1 in 101 chance of returning true.My PR fix this by changing the
integercall frominteger(0, 100)tointeger(1, 100), this way, Iflikelihoodis 0, it'll always return false.This also aligns the likelihood with the probability, meaning that a likelihood of 1 has a 1 in 100 chance, instead of 1 in 101 (since 0 was included).