Daniel Keep wrote:
Slightly off-topic, but I just found this and thought it might be of
interest.
http://mjolnirstudios.com/IanBullard/files/79ffbca75a75720f066d491e9ea935a0-10.php
For reference, here is the ASM source for the mentioned Flipcode random
number generator:
pshufw mm1, mm0, 0x1E
Benji Smith wrote:
Don wrote:
Benji Smith wrote:
Don wrote:
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it
would know its own boundaries, and it'
Hello Daniel,
Slightly off-topic, but I just found this and thought it might be of
interest.
http://mjolnirstudios.com/IanBullard/files/79ffbca75a75720f066d491e9ea
935a0-10.php
For reference, here is the ASM source for the mentioned Flipcode
random number generator:
pshufw mm1, mm0, 0x1E
pad
Don wrote:
Benji Smith wrote:
Don wrote:
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it
would know its own boundaries, and it'd keep track of whet
Slightly off-topic, but I just found this and thought it might be of
interest.
http://mjolnirstudios.com/IanBullard/files/79ffbca75a75720f066d491e9ea935a0-10.php
For reference, here is the ASM source for the mentioned Flipcode random
number generator:
> pshufw mm1, mm0, 0x1E
> paddd mm0, mm1
F
On Thu, 19 Feb 2009 11:35:04 +0300, Don wrote:
Benji Smith wrote:
Don wrote:
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its own
Benji Smith wrote:
Don wrote:
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its own boundaries, and it'd keep track of whether those
b
Don wrote:
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its own boundaries, and it'd keep track of whether those
boundaries were open
Nick Sabalausky wrote:
"Don" wrote in message
news:gnb7mt$2os...@digitalmars.com...
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its
"Don" wrote in message
news:gnb7mt$2os...@digitalmars.com...
> Andrei Alexandrescu wrote:
>> Benji Smith wrote:
>>> Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its own
On Fri, Feb 13, 2009 at 8:10 PM, Andrei Alexandrescu
wrote:
I feel like I'm mimicking everyone else by now, but:
> 1. Are you cool with making the rng the last parameter and give it a default
> value?
Yes.
> 2. The global random generator will be allocated per thread. Are you cool
> with this
Andrei Alexandrescu, el 13 de febrero a las 17:10 me escribiste:
> Leonardo suggested that some functions in std.random should not require their
> user to be bothered with creating a random object, i.e.:
>
> auto r = Random(unpredictableSeed);
> auto n = uniform(r, 0, 100);
>
> Instead the libra
Lionello Lunesu wrote:
"Andrei Alexandrescu" wrote in message
news:gnafec$1ck...@digitalmars.com...
Ok. Let me just note that rand()%max is a lousy method of generating
random numbers between 0 and max-1 and everybody should put that in
the bin with Popular Examples That Should Never Be Used
Andrei Alexandrescu wrote:
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its own boundaries, and it'd keep track of whether those
boundaries were open or closed.
Andrei Alexandrescu wrote:
Lionello Lunesu wrote:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
I love
On Sun, 15 Feb 2009 20:30:06 -0800, Andrei Alexandrescu wrote:
> Steve Schveighoffer wrote:
>> On Mon, 16 Feb 2009 12:20:34 +0900, Bill Baxter wrote:
>>
>>> On Mon, Feb 16, 2009 at 12:07 PM, Steve Schveighoffer
>>> wrote:
On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:
>
"Steve Schveighoffer" wrote in message
news:gnal9n$19a...@digitalmars.com...
On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:
Ok. Let me just note that rand()%max is a lousy method of generating
random numbers between 0 and max-1 and everybody should put that in the
bin with Po
"Andrei Alexandrescu" wrote in message
news:gnafec$1ck...@digitalmars.com...
Ok. Let me just note that rand()%max is a lousy method of generating
random numbers between 0 and max-1 and everybody should put that in the
bin with Popular Examples That Should Never Be Used, together with
exponen
Steve Schveighoffer wrote:
On Mon, 16 Feb 2009 12:20:34 +0900, Bill Baxter wrote:
On Mon, Feb 16, 2009 at 12:07 PM, Steve Schveighoffer
wrote:
On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:
Ok. Let me just note that rand()%max is a lousy method of generating
random numbers b
On Mon, 16 Feb 2009 12:20:34 +0900, Bill Baxter wrote:
> On Mon, Feb 16, 2009 at 12:07 PM, Steve Schveighoffer
> wrote:
>> On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:
>>
>>> Ok. Let me just note that rand()%max is a lousy method of generating
>>> random numbers between 0 and ma
On Mon, Feb 16, 2009 at 12:07 PM, Steve Schveighoffer
wrote:
> On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:
>
>> Ok. Let me just note that rand()%max is a lousy method of generating
>> random numbers between 0 and max-1 and everybody should put that in the
>> bin with Popular Exa
On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:
> Ok. Let me just note that rand()%max is a lousy method of generating
> random numbers between 0 and max-1 and everybody should put that in the
> bin with Popular Examples That Should Never Be Used, together with
> exponential Fibonac
Lionello Lunesu wrote:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
I love your templates as much as th
Lionello Lunesu wrote:
My point was that realloc() is wrong, not free(). The sorely missing
allocation primitive is expand(), and we've been paying for it through
the nose for decades.
Andrei
What would expand's signature be? It needs the current pointer, it needs
the new size. Seems that i
Andrei Alexandrescu wrote:
1. Are you cool with making the rng the last parameter and give it a
default value?
Yes.
2. The global random generator will be allocated per thread. Are you
cool with this too?
Yes.
3. How should the global rng be initialized? To always generate the same
sequen
My point was that realloc() is wrong, not free(). The sorely missing
allocation primitive is expand(), and we've been paying for it through
the nose for decades.
Andrei
What would expand's signature be? It needs the current pointer, it needs
the new size. Seems that it's nothing else than a
Benji Smith wrote:
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would
know its own boundaries, and it'd keep track of whether those
boundaries were open or closed.
The random functions would
Benji Smith wrote:
Maybe a NumericInterval struct would be a good idea. It could be
specialized to any numeric type (float, double, int, etc), it would know
its own boundaries, and it'd keep track of whether those boundaries were
open or closed.
The random functions would take an RND and an i
Andrei Alexandrescu wrote:
Steve Schveighoffer wrote:
4. While we're at it, should uniform(a, b) generate by default something
in [a, b] or [a, b)?
[a,b)
Every other piece of range-like code is zero based, and excludes the
upper bound. This should be no different. It makes the code simpler
On Mon, Feb 16, 2009 at 4:36 AM, Andrei Alexandrescu
wrote:
> Bill Baxter wrote:
>>
>> On Mon, Feb 16, 2009 at 4:07 AM, Andrei Alexandrescu
>> wrote:
>>>
>>> Bill Baxter wrote:
On Mon, Feb 16, 2009 at 3:51 AM, Andrei Alexandrescu
wrote:
>
> auto b = uniform!("[]")(rng, byt
Bill Baxter wrote:
On Mon, Feb 16, 2009 at 4:07 AM, Andrei Alexandrescu
wrote:
Bill Baxter wrote:
On Mon, Feb 16, 2009 at 3:51 AM, Andrei Alexandrescu
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
Andrei Alexandrescu wrote:
Joel C. Salomon wrote:
Don wrote:
There's a couple of difficult situations involving floating-point
numbers.
* any floating point range which includes 0 is difficult, because there
are so many numbers which are almost zero. The probability of getting a
zero for an
On Mon, Feb 16, 2009 at 4:07 AM, Andrei Alexandrescu
wrote:
> Bill Baxter wrote:
>>
>> On Mon, Feb 16, 2009 at 3:51 AM, Andrei Alexandrescu
>> wrote:
>>>
>>> auto b = uniform!("[]")(rng, byte.min, byte.max);
>>>
>>> Is this acceptable?
>>
>> If that's what it took I'd probably try this instead:
>
Joel C. Salomon wrote:
Don wrote:
There's a couple of difficult situations involving floating-point numbers.
* any floating point range which includes 0 is difficult, because there
are so many numbers which are almost zero. The probability of getting a
zero for an 80-bit real is so small that
Bill Baxter wrote:
On Mon, Feb 16, 2009 at 3:51 AM, Andrei Alexandrescu
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 di
On Mon, Feb 16, 2009 at 3:51 AM, Andrei Alexandrescu
wrote:
> Bill Baxter wrote:
>>
>> I guess I'd find it more useful to have a function that gave a random
>> value of a given type, like random_value!(short). That way you get
>> the signed/unsigned specification automatically. But both could be
Don wrote:
> There's a couple of difficult situations involving floating-point numbers.
> * any floating point range which includes 0 is difficult, because there
> are so many numbers which are almost zero. The probability of getting a
> zero for an 80-bit real is so small that you probably wouldn
Bill Baxter wrote:
I guess I'd find it more useful to have a function that gave a random
value of a given type, like random_value!(short). That way you get
the signed/unsigned specification automatically. But both could be
useful.
You can, just pass short values into uniform() or specify type
On Mon, Feb 16, 2009 at 3:41 AM, dsimcha wrote:
> == Quote from Bill Baxter (wbax...@gmail.com)'s article
>> On Mon, Feb 16, 2009 at 2:33 AM, Don Clugston wrote:
>> > Andrei Alexandrescu wrote:
>> >>
>> >> Don wrote:
>> >>>
>> >>> Andrei Alexandrescu wrote:
>>
>> auto rng = Random(unpre
Don:
> * I also think it'd be worth having a "create a random n-byte number",
> as well, which would be the main use for a full uint random number.
I mostly agree. For example a basic randUint is useful (I have it in dlibs and
I use it once in a while).
I think a randomUint and randUlong may be
On Mon, Feb 16, 2009 at 3:33 AM, Don wrote:
> Bill Baxter wrote:
>>
>> On Mon, Feb 16, 2009 at 2:33 AM, Don Clugston wrote:
>>>
>>> Andrei Alexandrescu wrote:
Don wrote:
>
> Andrei Alexandrescu wrote:
>>
>> auto rng = Random(unpredictableSeed);
>> auto a = 0.0, b = 1
== Quote from Bill Baxter (wbax...@gmail.com)'s article
> On Mon, Feb 16, 2009 at 2:33 AM, Don Clugston wrote:
> > Andrei Alexandrescu wrote:
> >>
> >> Don wrote:
> >>>
> >>> Andrei Alexandrescu wrote:
>
> auto rng = Random(unpredictableSeed);
> auto a = 0.0, b = 1.0;
> auto x1
Bill Baxter wrote:
On Mon, Feb 16, 2009 at 2:33 AM, Don Clugston wrote:
Andrei Alexandrescu wrote:
Don wrote:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("
On Mon, Feb 16, 2009 at 2:33 AM, Don Clugston wrote:
> Andrei Alexandrescu wrote:
>>
>> Don wrote:
>>>
>>> Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
Andrei Alexandrescu wrote:
Don wrote:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
This is a general i
Don:
> arr[random(0..arr.length)]
> is likely to be an _extremely_ common usage pattern. That argues very
> strongly for "[)".
For that there's choice():
choice(arr)
Bye,
bearophile
Walter Bright wrote:
Jason House wrote:
D uses a..b notation as part of the language to mean "[)". Because of
that, it makes more sense to make that the default in D vs. other
languages that don't have such constructs.
I think that's exactly right. Consistency is very important.
Agreed. Note
dsimcha wrote:
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article
Also, dsimcha said:
> This is purely a convenience feature for when you want
> random number generation to "just work" even if it's not the most
> efficient thing
> in the world.
I agree to him. If yo
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article
> > Also, dsimcha said:
> > > This is purely a convenience feature for when you want
> > > random number generation to "just work" even if it's not the most
> > > efficient thing
> > > in the world.
> >
> > I agree to h
Denis Koroskin wrote:
On Sat, 14 Feb 2009 21:38:19 +0300, Andrei Alexandrescu
wrote:
For 2 evaluations over a 10-integers array, reduce!(min),
reduce!("b > a ? b : a"), and handMax all finished within 3.4 to 3.5
seconds on my machine. The "normal" version took 11.6 seconds to
complete
grauzone wrote:
Andrei Alexandrescu wrote:
grauzone wrote:
dsimcha wrote:
== Quote from Walter Bright (newshou...@digitalmars.com)'s article
Andrei Alexandrescu wrote:
2. The global random generator will be allocated per thread. Are you
cool with this too?
That could have speed problems with
Derek Parnell wrote:
On Sat, 14 Feb 2009 19:07:52 +0200, Yigal Chripun wrote:
I see.
Having 3 functions: malloc(), expand() and free() is indeed a very good
design.
Unless you need to contract the allocated memory ;-) I believe that
realloc() does expansions and contractions, no?
use free
On Sat, 14 Feb 2009 14:11:10 +0300, Denis Koroskin wrote:
> On Sat, 14 Feb 2009 14:04:36 +0300, Walter Bright
> wrote:
>
>> Andrei Alexandrescu wrote:
>>> auto big = uniform(rng, uint.max / 2, uint.max);
>>> If the interval is open I can't generate uint.max.
>>
>>
>> auto big = uniform(rng, uin
On Sat, 14 Feb 2009 21:38:19 +0300, Andrei Alexandrescu
wrote:
grauzone wrote:
dsimcha wrote:
== Quote from Walter Bright (newshou...@digitalmars.com)'s article
Andrei Alexandrescu wrote:
2. The global random generator will be allocated per thread. Are you
cool with this too?
That could ha
Derek Parnell wrote:
On Sat, 14 Feb 2009 19:07:52 +0200, Yigal Chripun wrote:
I see.
Having 3 functions: malloc(), expand() and free() is indeed a very good
design.
Unless you need to contract the allocated memory ;-) I believe that
realloc() does expansions and contractions, no?
expand()
Derek Parnell wrote:
On Sat, 14 Feb 2009 19:07:52 +0200, Yigal Chripun wrote:
I see.
Having 3 functions: malloc(), expand() and free() is indeed a very good
design.
Unless you need to contract the allocated memory ;-) I believe that
realloc() does expansions and contractions, no?
expand(
On Sat, 14 Feb 2009 19:07:52 +0200, Yigal Chripun wrote:
> I see.
> Having 3 functions: malloc(), expand() and free() is indeed a very good
> design.
Unless you need to contract the allocated memory ;-) I believe that
realloc() does expansions and contractions, no?
--
Derek Parnell
Melbourne,
Walter Bright Wrote:
> Andrei Alexandrescu wrote:
> > 2. The global random generator will be allocated per thread. Are you
> > cool with this too?
>
> That could have speed problems with a tight loop accessing thread local
> storage. If it's a shared global with no locking, the thread randomnes
Jason House wrote:
D uses a..b notation as part of the language to mean "[)". Because of
that, it makes more sense to make that the default in D vs. other
languages that don't have such constructs.
I think that's exactly right. Consistency is very important.
Andrei Alexandrescu wrote:
grauzone wrote:
dsimcha wrote:
== Quote from Walter Bright (newshou...@digitalmars.com)'s article
Andrei Alexandrescu wrote:
2. The global random generator will be allocated per thread. Are you
cool with this too?
That could have speed problems with a tight loop ac
grauzone wrote:
dsimcha wrote:
== Quote from Walter Bright (newshou...@digitalmars.com)'s article
Andrei Alexandrescu wrote:
2. The global random generator will be allocated per thread. Are you
cool with this too?
That could have speed problems with a tight loop accessing thread local
storage
Walter Bright wrote:
grauzone wrote:
I don't understand this. If implemented right (D2.0 or gcc thread
variables), TLS can be as fast as a normal global variable. You only
need an additional check (a simple if()) to lazily initialize the RNG.
That's the notorious double-checked-locking bug, a
grauzone wrote:
I don't understand this. If implemented right (D2.0 or gcc thread
variables), TLS can be as fast as a normal global variable. You only
need an additional check (a simple if()) to lazily initialize the RNG.
That's the notorious double-checked-locking bug, an incredibly seductive
Denis Koroskin wrote:
On Sat, 14 Feb 2009 14:04:36 +0300, Walter Bright
wrote:
Andrei Alexandrescu wrote:
auto big = uniform(rng, uint.max / 2, uint.max);
If the interval is open I can't generate uint.max.
auto big = uniform(rng, uint.max / 2 - 1, uint.max) + 1;
Yeah, but now about uni
dsimcha wrote:
== Quote from Walter Bright (newshou...@digitalmars.com)'s article
Andrei Alexandrescu wrote:
2. The global random generator will be allocated per thread. Are you
cool with this too?
That could have speed problems with a tight loop accessing thread local
storage.
I don't think
Ary Borenszweig wrote:
Christopher Wright escribió:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
I alw
Andrei Alexandrescu wrote:
Yigal Chripun wrote:
Andrei Alexandrescu wrote:
bearophile wrote:
random() => floating point [0, 1)
randInt(a=0, b) => integral [a, b]
randRange(a=0, b) => integral [a, b)
uniform(a, b) => floating point [a, b)
normal(a, b) => good quality normally-distributed number
== Quote from Walter Bright (newshou...@digitalmars.com)'s article
> Andrei Alexandrescu wrote:
> > 2. The global random generator will be allocated per thread. Are you
> > cool with this too?
> That could have speed problems with a tight loop accessing thread local
> storage.
I don't think this m
Christopher Wright escribió:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
I always have to look up whet
Christopher Wright:
> I always have to look up whether "[]" is exclusive or inclusive.
A cute thing for you: where I live in Mathematics we use a different syntax:
[1, 10] <= closed interval
]1, 10[ <= open interval
[1, 10[ <= interval open on the right
]1, 10] <= interval open on the left
> So,
Yigal Chripun wrote:
Andrei Alexandrescu wrote:
bearophile wrote:
random() => floating point [0, 1)
randInt(a=0, b) => integral [a, b]
randRange(a=0, b) => integral [a, b)
uniform(a, b) => floating point [a, b)
normal(a, b) => good quality normally-distributed number with given
std dev and avg.
Don wrote:
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
This is a general issue applying to any numeric
Andrei Alexandrescu wrote:
auto rng = Random(unpredictableSeed);
auto a = 0.0, b = 1.0;
auto x1 = uniform!("[]")(rng, a, b);
auto x2 = uniform!("[)")(rng, a, b);
auto x3 = uniform!("(]")(rng, a, b);
auto x4 = uniform!("()")(rng, a, b);
I always have to look up whether "[]" is exclusive or inclu
Andrei Alexandrescu Wrote:
> Steve Schveighoffer wrote:
> >> 4. While we're at it, should uniform(a, b) generate by default something
> >> in [a, b] or [a, b)?
> >
> > [a,b)
> >
> > Every other piece of range-like code is zero based, and excludes the
> > upper bound. This should be no differen
Andrei Alexandrescu wrote:
bearophile wrote:
Andrei Alexandrescu:
3. How should the global rng be initialized?
Automatically seeded with the time at the beginning of the program. Of
course the seed can be set again in any moment.
4. While we're at it, should uniform(a, b) generate by defa
Andrei Alexandrescu wrote:
4. While we're at it, should uniform(a, b) generate by default something
in [a, b] or [a, b)? Someone once explained to me that generating [a, b]
for floating point numbers is the source of all evils and that Hitler,
Stalin and Kim Il Sung (should he still be alive) m
Fri, 13 Feb 2009 17:10:29 -0800, Andrei Alexandrescu wrote:
> 4. While we're at it, should uniform(a, b) generate by default something
> in [a, b] or [a, b)? Someone once explained to me that generating [a, b]
> for floating point numbers is the source of all evils and that Hitler,
> Stalin and
On Sat, 14 Feb 2009 14:04:36 +0300, Walter Bright
wrote:
Andrei Alexandrescu wrote:
auto big = uniform(rng, uint.max / 2, uint.max);
If the interval is open I can't generate uint.max.
auto big = uniform(rng, uint.max / 2 - 1, uint.max) + 1;
Yeah, but now about uniform(uint.min, uint.max
Andrei Alexandrescu wrote:
2. The global random generator will be allocated per thread. Are you
cool with this too?
That could have speed problems with a tight loop accessing thread local
storage. If it's a shared global with no locking, the thread randomness
will increase its randomness .
Andrei Alexandrescu wrote:
auto big = uniform(rng, uint.max / 2, uint.max);
If the interval is open I can't generate uint.max.
auto big = uniform(rng, uint.max / 2 - 1, uint.max) + 1;
Andrei Alexandrescu wrote:
Steve Schveighoffer wrote:
4. While we're at it, should uniform(a, b) generate by default something
in [a, b] or [a, b)?
[a,b)
Every other piece of range-like code is zero based, and excludes the
upper bound. This should be no different. It makes the code simpler
On Sat, Feb 14, 2009 at 3:04 PM, grauzone wrote:
>> Anyway, I checked the C++ API and it turns out they use closed intervals
>> for integers and open intervals for reals. I know there's been a lot of
>> expert scrutiny there, so I suppose I better copy their design.
>
> Because C++ is the pinnacle
grauzone wrote:
Anyway, I checked the C++ API and it turns out they use closed
intervals for integers and open intervals for reals. I know there's
been a lot of expert scrutiny there, so I suppose I better copy their
design.
Because C++ is the pinnacle of language and library design.
No, ju
Anyway, I checked the C++ API and it turns out they use closed intervals
for integers and open intervals for reals. I know there's been a lot of
expert scrutiny there, so I suppose I better copy their design.
Because C++ is the pinnacle of language and library design.
SCNR
Steve Schveighoffer wrote:
4. While we're at it, should uniform(a, b) generate by default something
in [a, b] or [a, b)?
[a,b)
Every other piece of range-like code is zero based, and excludes the
upper bound. This should be no different. It makes the code simpler too.
I tried both version
On Fri, 13 Feb 2009 17:10:29 -0800, Andrei Alexandrescu wrote:
> 2. The global random generator will be allocated per thread. Are you
> cool with this too?
Good idea. Random number generators should not require locking in the
most common case.
>
> 3. How should the global rng be initialized?
bearophile wrote:
When the phobos of D2 will be "finished" it will require one year or
more of "tuning" (discussing names here on the newsgroup) to find the
best names, API, etc.
I know. This is an exciting time to be around D!
Andrei
On Fri, 13 Feb 2009 17:10:29 -0800, Andrei Alexandrescu wrote:
> 1. Are you cool with making the rng the last parameter and give it a
> default value?
Yes
> 2. The global random generator will be allocated per thread. Are you
> cool with this too?
Yes
> 3. How should the global rng be ini
Daniel Keep:
> My pages of code implementing it in Python would like to disagree with
> you on that. So would the safety science guys I write simulation and
> analysis code for.
Python devs (and the same is true for other people, like Mathematica devs) have
seen such thing isn't a common need, I
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article
> Leonardo suggested that some functions in std.random should not require
> their user to be bothered with creating a random object, i.e.:
> auto r = Random(unpredictableSeed);
> auto n = uniform(r, 0, 100);
> Instead the l
bearophile wrote:
> Andrei Alexandrescu:
>> I don't see how having to memorize four names instead of one is necessarily
>> awesome and beautiful. Besides uniform() renders "random" redundant.
>> Hardly a pinnacle of good API design
>
> You never need this, so it's over-generalized, and it's al
Andrei Alexandrescu:
> Leaving normal() aside (does your implementation implement the ziggurat
> algorithm?
You can use two well known algorithms, one is a simple one, and the other is
more precise. The simple one is just to extract 10 or 12 uniform numbers and
sum them.
> I don't see how hav
bearophile wrote:
Andrei Alexandrescu:
3. How should the global rng be initialized?
Automatically seeded with the time at the beginning of the program. Of course
the seed can be set again in any moment.
4. While we're at it, should uniform(a, b) generate by default something
in [a, b] or
Andrei Alexandrescu:
> 3. How should the global rng be initialized?
Automatically seeded with the time at the beginning of the program. Of course
the seed can be set again in any moment.
> 4. While we're at it, should uniform(a, b) generate by default something
> in [a, b] or [a, b)? Someone
On Sat, 14 Feb 2009 04:10:29 +0300, Andrei Alexandrescu
wrote:
Leonardo suggested that some functions in std.random should not require
their user to be bothered with creating a random object, i.e.:
auto r = Random(unpredictableSeed);
auto n = uniform(r, 0, 100);
Instead the library should
Leonardo suggested that some functions in std.random should not require
their user to be bothered with creating a random object, i.e.:
auto r = Random(unpredictableSeed);
auto n = uniform(r, 0, 100);
Instead the library should simply support:
auto n = uniform(0, 100);
and do this by presumabl
96 matches
Mail list logo