spir <[email protected]> wrote:

===================
alias char[] Text ;

Text letters = ['a','b','c',...] ;

Text[] nameSet (uint count , uint size) {
        /* set of count random names of size size */
        Text[] names ; names.length = count ;
        Text name ; name.length = size ;
        for (int i=0 ; i<count ; i++) {
                for (int j=0 ; j<size ; j++)
                    name[j] = letters[uniform(0u,26u)] ;
                names[i].length = size ;
                names[i][] = name ;
        }
        return names ;
}
===================

Here's my version of the same, in highly unidiomatic D:

auto nameSet( uint count, uint size ) {
    auto randomWordsRandomLength = map!"a()"(
        repeat({
            return repeat({
                    return cast(char)iota(65,91)[ uniform( 0, 26 ) ];
            });
        })
    );

    return array( take( map!(
        ( randomWord ){
            return array( take( map!"a()"( randomWord ), size ) );
        })( randomWordsRandomLength ), count ) );
}


--
Simen

Reply via email to