www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2921] New: std.random.uniform doesn't work with char.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2921

           Summary: std.random.uniform doesn't work with char.
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: dsimcha yahoo.com


import std.random, std.stdio;

void main() {
    foreach(i; 0..1_000) {
        write(uniform!"[]"('A', 'Z'));
    }
}


Prints:  All A's.  If 'A' and 'Z' are cast to ubyte, the results look
reasonable.


-- 
May 02 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2921





------- Comment #1 from dsimcha yahoo.com  2009-05-03 14:41 -------
Created an attachment (id=346)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=346&action=view)
Make uniform work with chars.

It's just a problem of uniform trying to treat characters as if they were
floating point types because isIntegral!(char) is false.  Here's a patch that
just makes a new template isIntOrChar(T) and uses that instead.


-- 
May 03 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2921


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from andrei metalanguage.com  2009-05-03 15:53 -------
Thanks, fixed in svn.


-- 
May 03 2009