Random playlist algorithm

后端 未结 12 1522
北恋
北恋 2020-12-09 04:58

I need to create a list of numbers from a range (for example from x to y) in a random order so that every order has an equal chance.

I need this for a music player I

12条回答
  •  -上瘾入骨i
    2020-12-09 05:39

    I think you should stick to your current solution (the one in your edit).

    To do a re-order with no repetitions & not making your code behave unreliable, you have to track what you have already used / like by keeping unused indexes or indirectly by swapping from the original list.

    I suggest to check it in the context of the working application i.e. if its of any significance vs. the memory used by other pieces of the system.

提交回复
热议问题