Comments (2)
That's fair enough. I eventually came up with what I consider to be an acceptable workaround - I created my own implementation of IPick which takes in a single value and always returns that value. Then I just used a factory method to return either that in the 1-element case, or a normal picker in every other case.
from fluent-random-picker.
Hello, it was implemented like this for 2/3 reasons:
- consistency: The fluent syntax does not allow something like
Out.Of().Value(3).Pick()
. It compiles only when callingAndValue()
at least once. -
- In your case, it is an unexpected behavior, but in other cases, it could be useful, because maybe, someone has accidentally passed only 1 value.
- Especially when additionally specifying weights (e.g. "please pick form the following values: letter z with weight 37; that's it"), from the library point of view, it looks more like it received wrong input.
To be honest: I don't know what the best solution is (status you, your suggestion, allowing to configure the behavior) and I can't promise you to change the logic.
from fluent-random-picker.
Related Issues (19)
- Weight doesn't influence random values correctly.
- Percentages less than 1 HOT 7
- Allow specifying values + priorities in one step HOT 5
- Get rid of multiple enumerations of IEnumerables HOT 1
- Allow chaining Values(...).AndValues(...) ?
- Weights using long HOT 3
- Priorities don't matter in rare cases HOT 1
- OverflowException in SecureRandomNumberGenerator.NextInt()
- Support Span, ReadonlySpan, Memory, ReadOnlyMemory, ... HOT 1
- Use Reservoir sampling when 1 element (equal priorities) has to be picked
- Create implementation of `IRandomNumberGenerator` that is cryptographically secure HOT 1
- How can I give a small pool of reference types and pick a large number of items? HOT 3
- Improve documentation in code
- Consider extension methods
- PrioritizedElements.Pick(n) returns the same value n times HOT 1
- Try improving implementation of StochasticAcceptanceBasedWeightedLeftShuffle HOT 3
- Plan how to name the fluency interfaces consistently. HOT 1
- Improve performance with parallelization HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-random-picker.