shuffle

Randomly shuffle a List [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-08 19:36:16
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Randomize a List<T> in C# shuffle (rearrange randomly) a List<string> Random plot algorithm Hi I have the following list and I want to output the model into a list but do so randomly. I have seen a few examples but they seem to be really convuluted. I just want a simple way to do this? List<Car> garage ----randomise------> List<string> models List<Car> garage = new List<Car>(); garage.Add(new Car("Citroen", "AX"

Random Shuffling in Java (or any language) Probabilities [duplicate]

夙愿已清 提交于 2019-12-08 17:26:34
问题 This question already has answers here : What distribution do you get from this broken random shuffle? (10 answers) Closed 4 years ago . So, I'm watching Robert Sedgewick's videos on Coursera and I am currently at the Shuffling one. He's showing a "poorly written" shuffling code for online poker (it has a few other bugs, which I've removed because they are not related to my question) This is how the algorithm works: for(int i = 0; i < N; i++) int r = new Random().nextInt(53); swap(cardArray,

C++. Weighted std::shuffle

我只是一个虾纸丫 提交于 2019-12-08 17:26:26
问题 Is there a way to do nice and elegant weighted shuffling using standard library? There is std::discrete_distribution . What I want is something like this: std::vector<T> data { N elements }; std::vector<int> weights { N weights }; std::shuffle(std::begin(data), std::end(data), something based on discrete distribution); 回答1: If OP intent is to shuffle a list r of items such that, given a list of weights w , the element a[i] with weight w[i] should be the first element of the random shuffle r

Shuffle Playlist fix for Youtube API

人走茶凉 提交于 2019-12-08 11:26:12
问题 So while I was trying to create an embedded playlist on my website, and get it to shuffle, I found out that there is a bug in the YouTube API that wasn't fixed and won't let anyone use the Shuffle functionality. So I'm trying to create a work around. I figured I could make a Random number replace the index number of the playlist. That worked fine, and let me shuffle the playlist, as long as I manually entered the Max and Min for the Random number generator. see it here: http://jsfiddle.net

Select random elements from an array without repeats?

99封情书 提交于 2019-12-08 10:26:09
问题 edit: I can't believe I didn't catch this sooner. Turns out my problem was re-declaring my first variables over and over again, essentially starting the program fresh instead of continuing it. To fix it, I replaced the first two lines with this: if (initialized === undefined) { trace("INITIALIZING"); var MCs = []; var lastPos = "intializer"; var initialized = 1; } Now it works like a charm. I feel like a noob for this one; sorry to anyone whose time I wasted. I'd post this as an answer to my

How to shuffle array of implicit pairs?

坚强是说给别人听的谎言 提交于 2019-12-08 06:29:51
问题 I am trying to do shuffling of pairs in an array of images, and it is a little bit tricky for me. Example: I have 20 sequences of images, each containing 1000 frames .. they are saved in an array .. so let's assume, the array looks like that [[1_1],[1_2],[1_3],[1_4],[1_5],[1_6],[2_1],[2_2],[2_3],[2_4],[2_5],[2_6],[3_1],[3_2],[3_3],[3_4],[3_5],[3_6]] And so on, this is just a minimal example of 3 sequences, each having 6 frames .. but what I want to achieve in the end, of shuffling of

Select random <li> element

泪湿孤枕 提交于 2019-12-08 04:57:22
问题 I'm trying to make a shuffle button for my HTML 5 player. My player is set up like this to go the next track: $('.nextbutton').on("click", function(){ var next = $('li.playing').next(); if (!next.length) next = $('#stuff ul li').first(); next.addClass('playing').siblings().removeClass('playing'); var title = $('a#tunes img', next).attr("title"); $("a.songtitle span").text(title); var artist = $('a#tunes img', next).attr("artist"); $("a.songartist span").text(artist); audio.load($('a#tunes',

random_shuffle produces same results every time

落花浮王杯 提交于 2019-12-08 03:54:26
问题 Im trying to shuffle a deck of cards but random_shuffle produces the same result every time void Deck::shuffle() { cout << "SHUFFLING CARDS!!!\n\n"; srand(time(0)); random_shuffle(cards.begin(), cards.end()); displayCards(); } 回答1: That's because you seed pseudo-random number generator to the same value each time: srand(time(0)); The granularity of time are seconds, if I'm not mistaken. If you pause the execution for some time between calls to Deck::shuffle() you should see different results.

Javascript randomize array without having element in starting position [duplicate]

拟墨画扇 提交于 2019-12-08 02:38:10
问题 This question already has answers here : Shuffles Random Numbers with no repetition in Javascript/PHP (6 answers) Closed 5 years ago . I have a javascript problem. I have a user enter a list of names, which I then place into an array. Long story short, I am programming a random way for people to figure out who they will buy Christmas gifts for. For instance, the original array consists of the following names: Alex Joel Lindsay Cori I want to then randomize the names so that I get a random

Checking if iTunes is shuffling is not working

徘徊边缘 提交于 2019-12-07 21:56:40
问题 I'm developing a Mac App and I need to check if Itunes (11.0) is shuffling my music so, to check that, I'm using iTunes.h and the following code: if([iTunes.currentPlaylist shuffle]){ NSLog(@"yes"); }else{ NSLog(@"no"); } Even though I have my iTunes shuffling, it always outputs "no". Any ideas why is this happening or am I checking it the wrong way? 回答1: Good luck with that. I reported a bug about a month ago, like tons of other developers. Didn't hear anything, and probably won't. Like