[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 RazvanNchanged: What|Removed |Added Status|ASSIGNED|RESOLVED CC||razvan.nitu1...@gmail.com Resolution|--- |FIXED --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 --- Comment #13 from github-bugzi...@puremagic.com --- Commits pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/783d15bfa0e55d753999e7cc38236763c6b95092 enhancement issue 4851: add choice function to std.random https://github.com/dlang/phobos/commit/adb71a6c6b8e51680ce2337eb93c28fa7ea9a3fd enhancement issue 4851: use assert in choice function https://github.com/dlang/phobos/commit/6bc3a4f343ab653e85d11966a4b559da59c8 Merge pull request #4897 from edi33416/implement_choice --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 --- Comment #12 from github-bugzi...@puremagic.com --- Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/783d15bfa0e55d753999e7cc38236763c6b95092 enhancement issue 4851: add choice function to std.random https://github.com/dlang/phobos/commit/adb71a6c6b8e51680ce2337eb93c28fa7ea9a3fd enhancement issue 4851: use assert in choice function https://github.com/dlang/phobos/commit/6bc3a4f343ab653e85d11966a4b559da59c8 Merge pull request #4897 from edi33416/implement_choice --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 --- Comment #11 from github-bugzi...@puremagic.com --- Commits pushed to scope at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/783d15bfa0e55d753999e7cc38236763c6b95092 enhancement issue 4851: add choice function to std.random https://github.com/dlang/phobos/commit/adb71a6c6b8e51680ce2337eb93c28fa7ea9a3fd enhancement issue 4851: use assert in choice function https://github.com/dlang/phobos/commit/6bc3a4f343ab653e85d11966a4b559da59c8 Merge pull request #4897 from edi33416/implement_choice --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 --- Comment #10 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/783d15bfa0e55d753999e7cc38236763c6b95092 enhancement issue 4851: add choice function to std.random https://github.com/dlang/phobos/commit/adb71a6c6b8e51680ce2337eb93c28fa7ea9a3fd enhancement issue 4851: use assert in choice function https://github.com/dlang/phobos/commit/6bc3a4f343ab653e85d11966a4b559da59c8 Merge pull request #4897 from edi33416/implement_choice enhancement issue 4851: add choice function to std.random --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 Eduard Staniloiuchanged: What|Removed |Added Keywords||pull --- Comment #9 from Eduard Staniloiu --- I have created a PR that adds the choice function to std.random. The link is below: https://github.com/dlang/phobos/pull/4897 --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 Andrei Alexandrescuchanged: What|Removed |Added Assignee|nob...@puremagic.com|edi33...@gmail.com --
[Issue 4851] Three suggestions for std.random
https://issues.dlang.org/show_bug.cgi?id=4851 Andrei Alexandrescuchanged: What|Removed |Added Keywords||bootcamp --- Comment #8 from Andrei Alexandrescu --- Adding some of my own: * uniform!int should give a uniform, full-range int. Same of course for all integral types. * uniform!bool should give a random bit (economically, i.e. generate a new 64-bit number every 64 calls) * uniform!double should give a double in the range [0.0, 1.0). Or is [0.0, 1.0] more appropriate? * uniform!(int[])(30) should return an array of 30 integers * uniform!string(30) should return a uniform string of 30... bytes or code points? --
[Issue 4851] Three suggestions for std.random
https://d.puremagic.com/issues/show_bug.cgi?id=4851 --- Comment #7 from bearophile_h...@eml.cc 2014-03-29 16:13:21 PDT --- If choice returns a reference you can do: void knuthShuffle(T)(T[] r) { foreach_reverse (immutable i, ref ri; r[1 .. $ - 1]) r[0 .. i + 1].choice.swap(ri); } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 jens.k.muel...@gmx.de changed: What|Removed |Added CC||jens.k.muel...@gmx.de --- Comment #3 from jens.k.muel...@gmx.de 2013-02-23 05:12:55 PST --- How much of this request is still valid? From the documentation I find that 1. randomShuffle has default random generator 2. same for randomSample via overloads 3. choice can be expressed via auto choice = () = randomSample(r, 1, r.length).front; Missing piece is randomCover with a default RandomGen. Is this correct? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 bearophile_h...@eml.cc changed: What|Removed |Added AssignedTo|and...@erdani.com |nob...@puremagic.com --- Comment #4 from bearophile_h...@eml.cc 2013-02-23 05:24:37 PST --- (In reply to comment #3) 3. choice can be expressed via auto choice = () = randomSample(r, 1, r.length).front; That looks bad and it's error prone. It's not a replacement for choice() (and you have missed the input argument r). Missing piece is randomCover with a default RandomGen. Right. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 --- Comment #5 from jens.k.muel...@gmx.de 2013-02-23 05:49:23 PST --- (In reply to comment #4) (In reply to comment #3) 3. choice can be expressed via auto choice = () = randomSample(r, 1, r.length).front; That looks bad and it's error prone. It's not a replacement for choice() (and you have missed the input argument r). Right. Just for clarification. Adding auto choice(R)(R r) { return randomSample(r, 1, r.length).front; }; would be fine? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 --- Comment #6 from bearophile_h...@eml.cc 2013-02-23 09:45:45 PST --- (In reply to comment #5) Just for clarification. Adding auto choice(R)(R r) { return randomSample(r, 1, r.length).front; }; would be fine? When the input is an array (Random access range) I'd like it to use a items[uniform(0, $)]. So it's faster for the most common use case. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 --- Comment #2 from bearophile_h...@eml.cc 2011-04-16 12:54:38 PDT --- That fourth idea is also useful to avoid a little trap. This code looks correct, here randomCover() is used to act like the Python random.choice(), but here it keeps taking the same value: import std.stdio, std.random; void main() { // can't be const /*const*/ int[] data = [1, 2, 3, 4]; foreach (i; 0 .. 20) { int r = randomCover(data, rndGen).front; write(r, ); } } Output: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 The same bug can't happen with code like this, because the random generator is not created inside the foreach scope: import std.stdio, std.random; void main() { // can't be const /*const*/ int[] data = [1, 2, 3, 4]; foreach (i; 0 .. 20) { int r = randomCover(data).front; // int r = choice(data); // better write(r, ); } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 Andrei Alexandrescu and...@metalanguage.com changed: What|Removed |Added Status|NEW |ASSIGNED CC||and...@metalanguage.com AssignedTo|nob...@puremagic.com|and...@metalanguage.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4851] Three suggestions for std.random
http://d.puremagic.com/issues/show_bug.cgi?id=4851 --- Comment #1 from bearophile_h...@eml.cc 2010-09-12 18:56:32 PDT --- A fourth possible idea: RandomCover!(R, RandomGen) randomCover(R, RandomGen=Random)(R r, RandomGen gen=rndGen); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---