Bug 2921 – std.random.uniform doesn't work with char.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-05-02T12:25:00Z
Last change time
2015-06-09T01:26:26Z
Assigned to
bugzilla
Creator
dsimcha

Attachments

IDFilenameSummaryContent-TypeSize
346uniformChar.diffMake uniform work with chars.text/plain463

Comments

Comment #0 by dsimcha — 2009-05-02T12:25:21Z
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.
Comment #1 by dsimcha — 2009-05-03T14:41:51Z
Created attachment 346 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.
Comment #2 by andrei — 2009-05-03T15:53:48Z
Thanks, fixed in svn.