Hi All,
We discovered a bug yesterday and reported it:
https://forum.dlang.org/thread/mailman.1386.1662137084.31357.digitalmars-d-bugs@puremagic.com
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, DNA.max)).take(n);/*
auto preferred = generate!(() =>
uniform!"[]"(DNA.min,
DNA.max)).take(n);//*/
// # Alternative Solution:
foreach (_; 0..n)
{
gene ~= uniform!"[]"(DNA.min, DNA.max);
}
gene.writeln; // CGACGTGCTTCATCGATAGGAGCACGAGGAGC
// 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@79