legacy code retreat's triva game : the D version

bearophile bearophileHUGS at lycos.com
Sat Dec 21 07:03:33 PST 2013


Chris Cain:

> https://dl.dropboxusercontent.com/u/2206555/uniformUpgrade.pdf

 From page 6:

size_t[] counts = new size_t[](top);
foreach(i; 0 .. 500_000_000)
     counts[uniform(0, top)] += 1;


Modern D allows you to write better code:

size_t[N] counts;
foreach (immutable _; 0 .. 500_000_000)
     counts[uniform(0, $)]++;

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list