Error while generate DNA with uniform()

Salih Dincer salihdb at
Sat Sep 3 12:09:40 UTC 2022

Hi All,

We discovered a bug yesterday and reported it:

You know, there is `generate()` depend to `std.range`. It created 
the error when we use it with the value of an enum. Which get 
their values from an `enum DNA`, we have 4 members that we want 
to generate 32 pieces randomly like this:

import std;
void main()
   enum DNA { timin = 84,
              sitozin = 67,
              guanin = 71,
              adenin = 65
   char[] gene;
   enum n = 32;
   auto range = generate!(() => uniform(DNA.min, 
   auto preferred = generate!(() =>
   // # Alternative Solution:
   foreach (_; 0..n)
     gene ~= uniform!"[]"(DNA.min, DNA.max);
   // If the ASCII table matches (capital group 64-95) there 
should be no problem...

If there was no alternative solution, we would generate random 
numbers between 65 and 84 that have no equivalent in DNA. We want 
to use "[]" ( closed to the left and right)  but preferred 
version doesn't compile.

Can we solve this issue with our own `generate()` structure?

SDB at 79

More information about the Digitalmars-d-learn mailing list