[Issue 9339] std.random.uniform!Enum should return random enum member
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 17 16:52:14 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9339
--- Comment #5 from hsteoh at quickfur.ath.cx 2013-01-17 16:52:13 PST ---
(In reply to comment #3)
[...]
> I think this is more efficient:
>
>
> T uniform(T)()
> if (is(T == enum) && isIntegral!T || isSomeChar!T)
> {
> static immutable T[EnumMembers!T.length] members = [EnumMembers!T];
> return members[std.random.uniform(0, members.length)];
> }
You're right, we want the array to be statically initialized.
Does enum arr = [...] cause the code to create the array every time the
function is called?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list