0

重複の可能性:
セットの疑似ランダムトラバーサル

プレイリストの曲をランダムな順序にするアルゴリズムを作成しようとしているので、10 曲ある場合は、繰り返す前に 0 から 9 までのすべての値をヒットする乱数ジェネレーターが必要です。アルゴリズムを使用して: 、 aおよびx_current = (a * x_prev + c) mod mの特定の値でこれを達成する方法はありますか?cm

4

2 に答える 2

2

使ってみてstd::random_shuffle

 vector<int> playOrder;    

  // set some values:
  for (int i=1; i<10; ++i) playOrder.push_back(i); // 1 2 3 4 5 6 7 8 9

  // Don't forget to seed, or mix will be the same each run
  srand(time(NULL)); 

  // using built-in random generator:
  random_shuffle ( playOrder.begin(), playOrder.end() );

  // An example of how you might use the new random array.
  for(int i=0; i<playOrder.size(); i++)
    player.PlayTrack(playOrder[i]);
于 2012-11-11T01:35:34.310 に答える
0

この質問を見てください。また、小さなプレイリストの場合は、配列を曲番号でシャッフルするだけで十分です。

于 2012-11-11T01:35:06.287 に答える