default random object?
Bill Baxter
wbaxter at gmail.com
Sun Feb 15 11:57:42 PST 2009
On Mon, Feb 16, 2009 at 4:36 AM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Bill Baxter wrote:
>>
>> On Mon, Feb 16, 2009 at 4:07 AM, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>>
>>> Bill Baxter wrote:
>>>>
>>>> On Mon, Feb 16, 2009 at 3:51 AM, Andrei Alexandrescu
>>>> <SeeWebsiteForEmail at erdani.org> wrote:
>>>>>
>>>>> auto b = uniform!("[]")(rng, byte.min, byte.max);
>>>>>
>>>>> Is this acceptable?
>>>>
>>>> If that's what it took I'd probably try this instead:
>>>> ubyte b = uniform(rng, 0,256);
>>>>
>>>> And then add an explicit cast to ubyte if the compiler didn't like that.
>>>> So no, I don't really think that's good enough. Others may disagree
>>>> about how important a use case this is, though.
>>>
>>> This will indeed work:
>>>
>>> ubyte b = cast(ubyte) uniform(rng, 0,256);
>>>
>>> I just showed the solution involving no cast. So are you ok with that?
>>
>> No, but if you are then I'll just make my own 1-liner library
>> functions, so it's not a big deal.
>
> What signatures would the functions have?
What I'd like best is if all the things you listed would work, but in addition
T x = uniform!(T)();
would generate a uniform value over T's entire range, using a default
rng. And rng can be specified if you care what gets used:
T x = uniform!(T)(rng);
--bb
More information about the Digitalmars-d
mailing list