dimanche 2 janvier 2022

Algorithm for semi-randomly sorting a list [closed]

In my project, I have a list of random integers like this:

[20, 5, 1, 17, 4, 12]

Sorting this list from greatest to least is pretty easy. All major programming languages have a sort() function of some kind.

What I'm curious about is a form of sorting where list elements are mostly sorted from greatest to least, but with some provided "randomness" variable for how likely it is that the order will be shuffled around.

  1. If randomness = 0%, the list will be sorted perfectly every time.
  2. If randomness = 100%, every list element has an equal chance of ending up in any given spot - it's a total random shuffle.
  3. In between those two extremes, there are coherent possibilities where the list will be partially sorted, but retaining some disorganization proportional to the "randomness" variable.

Are there algorithms like this out there? What are the simplest ways to go about this process?

Thanks!




Aucun commentaire:

Enregistrer un commentaire