-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for single item generation #5
Comments
Sorry do not quite get what you mean by "I require a single random item at a time". Also I personally do not have a problem with But I do have a couple of problems with this:
I feel this is pretty much done and don't think tinkering more with it could be useful. |
Regarding bullet points 2 and 3: The closure of The problem was related to the fact that the default constructor of
I do understand that you're fine with What I mean by "I require a single random item at a time" is that I need only 1 random item at a time, not the whole series of them. As an example think of a message handler that needs to get a single random country:
I personally would rather write:
The above is a matter of personal preferences but also IMHO the principle of the least surprise (http://www.faqs.org/docs/artu/ch11s01.html). I can imagine that On the other hand I don't think that the following two methods can be confusing due to singular / plural naming and different return types. They read very 'English' and natural to me.
|
No, it was correct - why have you changed it to static?! Please note that the creation of var random = new Random();
return () => (random.NextDouble() < 0.5); |
Yes, but calling two var integers = Gen.Random.Numbers.Integers();
var doubles = Gen.Random.Numbers.Doubles(); Also, MSDN documentation has the following section regarding multiple initialisations:
|
Exactly! That is why we return a factory not the random number itself. I think we can randomise the seed so we are both happy... how about that? Or actually basing it on RNG... |
One of the reasons I did not RNG to begin with was that it is a disposable resource and I did not want any of that headache. So I think this should be pretty fine: new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 10)) |
I'll make the changes necessary. I presume you're not interested in single item API? |
I think it is a good idead but honestly it can make it confusing on how to use the API. We should drive them to the pit of success 🎱 |
Curently RandomGen supports creation of generators (
Func<T>
) that can be used to obtain a series of random items.I found that in most cases I require a single random item at a time.
The solution is to either store the generators (
Func<T>
) and reuse them between calls or to evaluate the function instantly (Gen.Random.Numbers.Integers()()
) which doesn't look nice in code()()
.What I would like to be able to do is write just:
var number = Gen.Random.Numbers.Integers();
.I would like to propose that we create an additional set of methods that would compliment the existing ones and allow for single items to be generated:
Func<int> Gen.Random.Numbers.Integers()
int Gen.Random.Number.Integer()
The text was updated successfully, but these errors were encountered: