samedi 3 août 2019

How to randomly select numbers in a sequence [duplicate]

This question already has an answer here:

Please consider these numbers:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

I want an efficient algorithm that randomly select one of above numbers and put them Continuous.For example:

8, 2, 1, 10, 4, 3, 5, 9, 7, 6
or
1, 9, 3, 10, 6, 5, 8, 7, 2, 4

Is there any algorithm with O(n)?

Thanks




Aucun commentaire:

Enregistrer un commentaire