digitalmars.D.learn - Invalid bounding interval [, ]
- C (21/21) Jan 24 2012 I want to fill a ubyte array with random data.
- bearophile (11/12) Jan 24 2012 In D ubytes are not char, they are two different types. So if you want u...
- Timon Gehr (3/15) Jan 24 2012 Even more reduced test case and bug report:
- Timon Gehr (4/25) Jan 24 2012 The code wouldn't do what you intended even if it compiled. Use this:
- C (7/9) Jan 25 2012 Thank you all for your replies.
- Timon Gehr (5/14) Jan 25 2012 Yes it does. But this works too and is probably more intuitive if you
- Era Scarecrow (4/7) Jan 25 2012 I think I can answer this.
I want to fill a ubyte array with random data. The code compiles with no warnings or errors. Source snippet: auto prng = Random(unpredictableSeed); ubyte[] chunk; chunk.length = 1024; fill(chunk, uniform!("[]")('\x00', '\xFF', prng)); Error (at runtime): object.Exception c:\dmd2\windows\bin\..\..\src\phobos\std\random.d(971): std.random.uniform(): invalid bounding interval [ , ] ---------------- 423C50 423AC7 404EA8 404EEC 404AE3 4A6109 ---------------- Also I lost the URL for this forum, all I see is this nasty PHP News Reader interface. Thank you.
Jan 24 2012
C:I want to fill a ubyte array with random data.In D ubytes are not char, they are two different types. So if you want ubytes, then use ubytes: uniform!("[]")(ubyte.min, ubyte.max) Regarding your error, a reduced test case: import std.random: uniform; void main() { uniform!("[]")(char.min, char.max); uniform!("(]")(char.min, char.max); } Bye, bearophile
Jan 24 2012
On 01/25/2012 04:50 AM, bearophile wrote:C:Even more reduced test case and bug report: http://d.puremagic.com/issues/show_bug.cgi?id=7367I want to fill a ubyte array with random data.In D ubytes are not char, they are two different types. So if you want ubytes, then use ubytes: uniform!("[]")(ubyte.min, ubyte.max) Regarding your error, a reduced test case: import std.random: uniform; void main() { uniform!("[]")(char.min, char.max); uniform!("(]")(char.min, char.max); } Bye, bearophile
Jan 24 2012
On 01/25/2012 04:25 AM, C wrote:I want to fill a ubyte array with random data. The code compiles with no warnings or errors. Source snippet: auto prng = Random(unpredictableSeed); ubyte[] chunk; chunk.length = 1024; fill(chunk, uniform!("[]")('\x00', '\xFF', prng)); Error (at runtime): object.Exception c:\dmd2\windows\bin\..\..\src\phobos\std\random.d(971): std.random.uniform(): invalid bounding interval [ , �] ---------------- 423C50 423AC7 404EA8 404EEC 404AE3 4A6109 ---------------- Also I lost the URL for this forum, all I see is this nasty PHP News Reader interface. Thank you.The code wouldn't do what you intended even if it compiled. Use this: auto chunk = new ubyte[1024]; foreach(ref x; chunk) x = uniform!"[]"(ubyte.min, ubyte.max);
Jan 24 2012
auto chunk = new ubyte[1024]; foreach(ref x; chunk) x = uniform!"[]"(ubyte.min, ubyte.max);Thank you all for your replies. Timon, I have two questions: 1) How come you can omit parentheses for uniform's parameter, shouldn't it be uniform!("[]")(...) ? 2) Does auto chunk = new ubyte[1024]; ALWAYS create a dynamic array with changeable length? That is a silly question but the syntax confuses me.
Jan 25 2012
On 01/25/2012 12:28 PM, C wrote:If there is only one template argument, parentheses can be omitted.auto chunk = new ubyte[1024]; foreach(ref x; chunk) x = uniform!"[]"(ubyte.min, ubyte.max);Thank you all for your replies. Timon, I have two questions: 1) How come you can omit parentheses for uniform's parameter, shouldn't it be uniform!("[]")(...) ?2) Does auto chunk = new ubyte[1024]; ALWAYS create a dynamic array with changeable length? That is a silly question but the syntax confuses me.Yes it does. But this works too and is probably more intuitive if you are not familiar with other C-derived languages: auto chunk = new ubyte[](1024);
Jan 25 2012
1) How come you can omit parentheses for uniform's parameter, shouldn't it be uniform!("[]")(...) ?I think I can answer this. With ! already being used, it already knows it's a template and is separating your argument. Being as you only have 1 argument, it's allowed. That's why you can see to!string(x) and to!(string)(x). At least that's how I understand it. If you have more than 1 argument for your template say for 'T2 fromTo(T, T2)(T t)', it has to be in parentheses. Not only would something like 'fromTo!int!string(x)' be difficult to read (and ugly, feels like :: for c++), it would probably be a pain on the compiler and syntax checker. So the second one would be 'fromTo!(int, string)(x)'. Etc. A good number of things are syntactical sugar, making lives easier :)
Jan 25 2012