Re: OT: random random stuff [Was: Re: default random object?]

2009-02-20 Thread Don
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

Re: default random object?

2009-02-19 Thread Don
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'

Re: OT: random random stuff [Was: Re: default random object?]

2009-02-19 Thread BCS
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

Re: default random object?

2009-02-19 Thread Benji Smith
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

OT: random random stuff [Was: Re: default random object?]

2009-02-19 Thread Daniel Keep
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

Re: default random object?

2009-02-19 Thread Denis Koroskin
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

Re: default random object?

2009-02-19 Thread Don
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

Re: default random object?

2009-02-18 Thread Benji Smith
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

Re: default random object?

2009-02-17 Thread Don
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

Re: default random object?

2009-02-16 Thread Nick Sabalausky
"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

Re: default random object?

2009-02-16 Thread Jarrett Billingsley
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

Re: default random object?

2009-02-16 Thread Leandro Lucarella
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

Re: default random object?

2009-02-16 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-16 Thread Don
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.

Re: default random object?

2009-02-16 Thread Don
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

Re: default random object?

2009-02-15 Thread Steve Schveighoffer
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: >

Re: default random object?

2009-02-15 Thread Lionello Lunesu
"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

Re: default random object?

2009-02-15 Thread Lionello Lunesu
"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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Steve Schveighoffer
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

Re: default random object?

2009-02-15 Thread Bill Baxter
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

Re: default random object?

2009-02-15 Thread Steve Schveighoffer
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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Lionello Lunesu
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

Re: default random object?

2009-02-15 Thread Lionello Lunesu
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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Benji Smith
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

Re: default random object?

2009-02-15 Thread Benji Smith
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

Re: default random object?

2009-02-15 Thread Bill Baxter
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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Don
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

Re: default random object?

2009-02-15 Thread Bill Baxter
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: >

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Bill Baxter
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

Re: default random object?

2009-02-15 Thread Joel C. Salomon
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

Re: default random object?

2009-02-15 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-15 Thread Bill Baxter
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

Re: default random object?

2009-02-15 Thread bearophile
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

Re: default random object?

2009-02-15 Thread Bill Baxter
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

Re: default random object?

2009-02-15 Thread dsimcha
== 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

Re: default random object?

2009-02-15 Thread Don
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!("

Re: default random object?

2009-02-15 Thread Bill Baxter
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);

Re: default random object?

2009-02-15 Thread Don Clugston
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

Re: default random object?

2009-02-15 Thread bearophile
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

Re: default random object?

2009-02-15 Thread Don
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

Re: default random object?

2009-02-14 Thread grauzone
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

Re: default random object?

2009-02-14 Thread dsimcha
== 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

Re: default random object?

2009-02-14 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-14 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-14 Thread Yigal Chripun
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

Re: default random object?

2009-02-14 Thread Steve Schveighoffer
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

Re: default random object?

2009-02-14 Thread Denis Koroskin
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

Re: default random object?

2009-02-14 Thread grauzone
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()

Re: default random object?

2009-02-14 Thread Andrei Alexandrescu
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(

Re: default random object?

2009-02-14 Thread Derek Parnell
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,

Re: default random object?

2009-02-14 Thread Jason House
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

Re: default random object?

2009-02-14 Thread Walter Bright
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.

Re: default random object?

2009-02-14 Thread grauzone
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

Re: default random object?

2009-02-14 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-14 Thread grauzone
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

Re: default random object?

2009-02-14 Thread Walter Bright
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

Re: default random object?

2009-02-14 Thread Walter Bright
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

Re: default random object?

2009-02-14 Thread grauzone
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

Re: default random object?

2009-02-14 Thread Christopher Wright
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

Re: default random object?

2009-02-14 Thread Yigal Chripun
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

Re: default random object?

2009-02-14 Thread dsimcha
== 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

Re: default random object?

2009-02-14 Thread Ary Borenszweig
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

Re: default random object?

2009-02-14 Thread bearophile
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,

Re: default random object?

2009-02-14 Thread Andrei Alexandrescu
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.

Re: default random object?

2009-02-14 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-14 Thread Christopher Wright
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

Re: default random object?

2009-02-14 Thread Jason House
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

Re: default random object?

2009-02-14 Thread Yigal Chripun
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

Re: default random object?

2009-02-14 Thread Don
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

Re: default random object?

2009-02-14 Thread Sergey Gromov
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

Re: default random object?

2009-02-14 Thread Denis Koroskin
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

Re: default random object?

2009-02-14 Thread Walter Bright
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 .

Re: default random object?

2009-02-14 Thread Walter Bright
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;

Re: default random object?

2009-02-13 Thread KennyTM~
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

Re: default random object?

2009-02-13 Thread Bill Baxter
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

Re: default random object?

2009-02-13 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-13 Thread grauzone
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

Re: default random object?

2009-02-13 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-13 Thread Steve Schveighoffer
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?

Re: default random object?

2009-02-13 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-13 Thread Derek Parnell
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

Re: default random object?

2009-02-13 Thread bearophile
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

Re: default random object?

2009-02-13 Thread dsimcha
== 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

Re: default random object?

2009-02-13 Thread Daniel Keep
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

Re: default random object?

2009-02-13 Thread bearophile
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

Re: default random object?

2009-02-13 Thread Andrei Alexandrescu
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

Re: default random object?

2009-02-13 Thread bearophile
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

Re: default random object?

2009-02-13 Thread Denis Koroskin
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

default random object?

2009-02-13 Thread Andrei Alexandrescu
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