Re: generating random numbers

2020-08-13 Thread Andy Balba via Digitalmars-d-learn
On Monday, 10 August 2020 at 15:43:04 UTC, Andy Balba wrote: On Monday, 10 August 2020 at 15:13:51 UTC, bachmeier wrote: On Monday, 10 August 2020 at 14:20:23 UTC, bachmeier wrote: On Monday, 10 August 2020 at 05:51:07 UTC, Andy Balba wrote: generating random numbers using https://dlang.org

Re: generating random numbers

2020-08-10 Thread Andy Balba via Digitalmars-d-learn
On Monday, 10 August 2020 at 15:13:51 UTC, bachmeier wrote: On Monday, 10 August 2020 at 14:20:23 UTC, bachmeier wrote: On Monday, 10 August 2020 at 05:51:07 UTC, Andy Balba wrote: generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in

Re: generating random numbers

2020-08-10 Thread bachmeier via Digitalmars-d-learn
On Monday, 10 August 2020 at 14:20:23 UTC, bachmeier wrote: On Monday, 10 August 2020 at 05:51:07 UTC, Andy Balba wrote: generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in this section totally incomprehensible .. Can any help me

Re: generating random numbers

2020-08-10 Thread bachmeier via Digitalmars-d-learn
On Monday, 10 August 2020 at 05:51:07 UTC, Andy Balba wrote: generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in this section totally incomprehensible .. Can any help me answer two simple questions: How to generate a random floating

Re: generating random numbers

2020-08-10 Thread James Blachly via Digitalmars-d-learn
On 8/10/20 1:51 AM, Andy Balba wrote: generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in this section totally incomprehensible .. Can any help me answer two simple questions: How to generate a random floating number in range [0,1

Re: generating random numbers

2020-08-09 Thread Ali Çehreli via Digitalmars-d-learn
On 8/9/20 10:51 PM, Andy Balba wrote: generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in this section totally incomprehensible ... Can any help me answer two simple questions: How to generate a random floating number in range [0,1

generating random numbers

2020-08-09 Thread Andy Balba via Digitalmars-d-learn
generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in this section totally incomprehensible .. Can any help me answer two simple questions: How to generate a random floating number in range [0,1) ? How to set a seed value, prior to

Re: Speed of Random Numbers

2019-08-04 Thread Daniel Kozak via Digitalmars-d-learn
On Sun, Aug 4, 2019 at 11:49 AM Daniel Kozak wrote: > > You can try http://code.dlang.org/packages/mir-random > > I am using theme here: > https://github.com/TechEmpower/FrameworkBenchmarks/blob/b9cc153dcd1c20e78197b0191536f0d11b8ca554/frameworks/D/vibed/source/postgresql.d#L49 > > On Sun, Aug 4,

Re: Speed of Random Numbers

2019-08-04 Thread Daniel Kozak via Digitalmars-d-learn
You can try http://code.dlang.org/packages/mir-random I am using theme here: https://github.com/TechEmpower/FrameworkBenchmarks/blob/b9cc153dcd1c20e78197b0191536f0d11b8ca554/frameworks/D/vibed/source/postgresql.d#L49 On Sun, Aug 4, 2019 at 12:20 AM Giovanni Di Maria via Digitalmars-d-learn wrote

Re: Speed of Random Numbers

2019-08-03 Thread Giovanni Di Maria via Digitalmars-d-learn
Thank you very much to Everybody! Giovanni

Re: Speed of Random Numbers

2019-08-03 Thread matheus via Digitalmars-d-learn
On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: For me the "goodness of random" is NOT important. If that's the case, you could roll your own RNG: //DMD64 D Compiler 2.072.2 import std.stdio; import std.datetime; import std.array, std.random; void main(){ ubyte x;

Re: Speed of Random Numbers

2019-08-03 Thread bauss via Digitalmars-d-learn
On Saturday, 3 August 2019 at 17:47:46 UTC, Giovanni Di Maria wrote: On Saturday, 3 August 2019 at 17:44:44 UTC, lithium iodate wrote: On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: [...] First off you could try to use a faster RNG engine than the default. The easiest w

Re: Speed of Random Numbers

2019-08-03 Thread Dennis via Digitalmars-d-learn
On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: Do you know other faster functions or methods to generate random numbers? For me the "goodness of random" is NOT important. I found some nice random functions in this public-domain C single-header library colle

Re: Speed of Random Numbers

2019-08-03 Thread Giovanni Di Maria via Digitalmars-d-learn
On Saturday, 3 August 2019 at 17:44:44 UTC, lithium iodate wrote: On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: [...] First off you could try to use a faster RNG engine than the default. The easiest way is to define a variable containing it and passing it to the functi

Re: Speed of Random Numbers

2019-08-03 Thread lithium iodate via Digitalmars-d-learn
On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: Do you know other faster functions or methods to generate random numbers? For me the "goodness of random" is NOT important. Thank you very much GIovanni Di Maria First off you could try to use a faster RNG engin

Re: Speed of Random Numbers

2019-08-03 Thread Giovanni Di Maria via Digitalmars-d-learn
viour and shot dispersion: they generated a static table of 256 random numbers once and any time they needed a random byte they just picked the next in the table. They didn't have any security or sciency concern and just wanted to provide a different game each time so that worked well for

Re: Speed of Random Numbers

2019-08-03 Thread Cym13 via Digitalmars-d-learn
On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: Hi to everybody I am doing some experiments about random numbers. I need "extreme speed" for the generation for numbers from 1 to 8. Generating 500_000_000 numbers with this code: --

Speed of Random Numbers

2019-08-03 Thread Giovanni Di Maria via Digitalmars-d-learn
Hi to everybody I am doing some experiments about random numbers. I need "extreme speed" for the generation for numbers from 1 to 8. Generating 500_000_000 numbers with this code: - import std.stdio, std.array, std.random; void main() { byte c;

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 20:22:23 UTC, Philippe Sigaud wrote: On Sat, Aug 4, 2012 at 7:27 PM, Ralph Main wrote: I tried the code in just main() like bearophile's post, and it worked just fine. I also removed the new keyword from my program and it compiled. The error message that I go

Re: Random Numbers

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 7:27 PM, Ralph Main wrote: > I tried the code in just main() like bearophile's post, and it worked just > fine. I also removed the new keyword from my program and it compiled. > > The error message that I got yesterday with the example code returned an > error message that

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 17:45:19 UTC, Ralph Main wrote: On Saturday, 4 August 2012 at 17:02:19 UTC, bearophile wrote: Ralph Main: The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: //

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 17:02:19 UTC, bearophile wrote: Ralph Main: The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: // Generate a uniformly-distributed integer in the range [0, 14]

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 16:59:09 UTC, Philippe Sigaud wrote: On Sat, Aug 4, 2012 at 6:40 PM, Ralph Main wrote: Hello Ralph, The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: (snip) Bo

Re: Random Numbers

2012-08-04 Thread bearophile
Ralph Main: The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: // Generate a uniformly-distributed integer in the range [0, 14] auto i = uniform(0, 15); // Generate a uniformly-dis

Re: Random Numbers

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 6:40 PM, Ralph Main wrote: Hello Ralph, > The module std.random documentation doesn't work as per the examples. > The example shows getting a random number by the following code does not > work: (snip) Both code samples you gave work perfectly for me (DMD 2.060, Linux). W

Random Numbers

2012-08-04 Thread Ralph Main
Gotchas! The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: // Generate a uniformly-distributed integer in the range [0, 14] auto i = uniform(0, 15); // Generate a uniformly-distri

Re: Range of random numbers

2012-04-25 Thread Christophe Travert
"bearophile" , dans le message (digitalmars.D.learn:35148), a écrit : > Why don't you write a little benchmark to compare the performance > of the two versions? Because I'm interested in the code's meaning for the human reader, not the performance. I actually think : "map!(_=> uniform(a, b))(re

Re: Range of random numbers

2012-04-24 Thread Joseph Rushton Wakeling
On 24/04/12 13:50, Christophe wrote: We could also use a template to make a range out of a delegate and avoid this workarround... What I'd _really_ like to see is something which would allow you to generate a range of random numbers with an expression like, auto rr = random

Re: Range of random numbers

2012-04-24 Thread bearophile
trav...@phare.normalesup.org: That looks like a workarround, not meaningful code. It wasn't terrible code :-) How about return repeat(_ =>uniform(lower, upper)).map!(x => x())(); ? Why don't you write a little benchmark to compare the performance of the two versions? Using uniform(lo

Re: Range of random numbers

2012-04-24 Thread Christophe
"bearophile" , dans le message (digitalmars.D.learn:35108), a écrit : > What about (untested): > > auto uniformRange(T1 lower, T2 upper) { > return count().map!(_ => uniform(lower, upper))(); > } That looks like a workarround, not meaningful code. How about return repeat(_ =>uniform(lower

Re: Range of random numbers

2012-04-23 Thread bearophile
Count(5) is easy to replace with iota(5, int.max), This also means that for the OP problem, using repeat(0) is more correct than using count(), because count on default yields ints, that are limited to about 2 milliards. Bye, bearophile

Re: Range of random numbers

2012-04-23 Thread bearophile
jerro: Couldn't it just be iota with no parameters? The Count range has a helper count() function similar to this, that's meant to have an argument that defaults to zero: Count!T count(T)(T start=0) if (isIntegral!T) { return Count!T(start); } The argument allows it to start from another

Re: Range of random numbers

2012-04-23 Thread jerro
It's for a different purpose. So the count() I was proposing will need a different name. Couldn't it just be iota with no parameters?

Re: Range of random numbers

2012-04-23 Thread Ali Çehreli
On 04/23/2012 10:56 AM, Joseph Rushton Wakeling wrote: On 23/04/12 19:46, Joseph Rushton Wakeling wrote: On 23/04/12 18:56, bearophile wrote: jerro: return repeat(0).map!(_ => uniform(lower, upper))(); Yes, this works nicely. Thanks very much! Is this a new addition? With GDC I get a com

Re: Range of random numbers

2012-04-23 Thread Joseph Rushton Wakeling
On 23/04/12 19:46, Joseph Rushton Wakeling wrote: On 23/04/12 18:56, bearophile wrote: jerro: return repeat(0).map!(_ => uniform(lower, upper))(); Yes, this works nicely. Thanks very much! Is this a new addition? With GDC I get a compiler error: expression expected, not '>' ... sugge

Re: Range of random numbers

2012-04-23 Thread Joseph Rushton Wakeling
On 23/04/12 18:56, bearophile wrote: jerro: return repeat(0).map!(_ => uniform(lower, upper))(); repeat(0) returns the same sequence as cycle([0]) and is as fast as it gets, since popFront does nothing and empty is an enum. Good idea. Yes, this works nicely. Thanks very much!

Re: Range of random numbers

2012-04-23 Thread bearophile
jerro: > return repeat(0).map!(_ => uniform(lower, upper))(); > > repeat(0) returns the same sequence as cycle([0]) and is as fast > as it gets, since popFront does nothing and empty is an enum. Good idea. --- Dmitry Olshansky: > What's wrong with: > http://dlang.org/phobos/st

Re: Range of random numbers

2012-04-23 Thread jerro
What about (untested): auto uniformRange(T1 lower, T2 upper) { return count().map!(_ => uniform(lower, upper))(); } Where count() is just: http://d.puremagic.com/issues/show_bug.cgi?id=7839 In the meantime cycle([0]) is acceptable but slower (untested): return cycle([0]).map!(_ => uniform(

Re: Range of random numbers

2012-04-23 Thread Dmitry Olshansky
On 23.04.2012 17:52, bearophile wrote: Joseph Rushton Wakeling: struct UniformRange(T1, T2) { T1 _lower; T2 _upper; @property enum bool empty = false; this(T1 a, T2 b) { _lower = a; _upper = b; } @property auto ref front() { assert(!empty); return uniform(_lower, _upper); } void popFront()

Re: Range of random numbers

2012-04-23 Thread bearophile
Joseph Rushton Wakeling: struct UniformRange(T1, T2) { T1 _lower; T2 _upper; @property enum bool empty = false; this(T1 a, T2 b) { _lower = a; _upper = b; } @property auto ref front()

Range of random numbers

2012-04-23 Thread Joseph Rushton Wakeling
For some reason this got lost in the ether, so I'm resending. Related to my earlier question on passing a function -- I was wondering if there's a trivial way of generating a lazily-evaluated range of random numbers according to a given distribution and parameters. I wrote up the

Range of n random numbers

2012-04-22 Thread Joseph Rushton Wakeling
Related to my earlier question -- I was wondering if there's a trivial way of generating a range of n random numbers according to a given distribution and parameters. I wrote up the code below to generate a range of n uniformly-distributed numbers, but am not sure how to generalize i