Fixed-size arrays and randomShuffle()

Vidar Wahlberg canidae at exent.net
Thu May 3 06:55:28 PDT 2012


On 2012-05-03 15:34, Ali Çehreli wrote:
> Fixed-length arrays are value types. 'a' is copied to randomShuffle() so
> its copy is shuffled. Passing a slice of the whole array works:
>
> randomShuffle(a[]);

True, it is however still not exceptionally newbie (or perhaps even 
user?) friendly (my question was more of "does it have to be this way?" 
rather than "how do you do this?", even though I appreciate the answer 
on how to do it).
Is it not possible for the compilator to let you know that what you're 
doing doesn't make any sense?

A quick follow-up:
I've tried some various random number engines, but neither come even 
close to the performance of whatever is used for Java's 
"Collection.shuffle()" method. Perhaps someone can shed some light on this?


More information about the Digitalmars-d-learn mailing list