lundi 29 juin 2020

Generate random numbers parallelly such that no two consecutives are same

I want to generate numbers from 0 to 5 parallelly such that no two consecutives are same. The approach below lead to many instances of numbers getting repeated consecutively. I have asked previously on how to avoid consecutive repetitions while generating numbers (Random number generation giving same numbers few times consecutively) but am still not sure of how to do this in a parallel environment .

     Random random = new Random();

        Parallel.For(0,100,(i)=>{
         int num   = random.Next(5);
            Console.WriteLine(num);
        });
           



Aucun commentaire:

Enregistrer un commentaire