Questions tagged [shuffle]

Shuffling is the act of randomizing the order of the elements in a collection. Sometimes the term shuffling is also used for reordering elements in a controllable way, e.g. the bytes within a vector, especially by respective instructions for SIMD architectures.

Shuffling is the process by which the order of the elements in a collection is randomized. The term shuffling is often used for playing cards.

One effective algorithm for doing so is Fischer-Yates Shuffle:

For a zero-based collection of n elements:

  1. Let i = n

  2. Let j = random integer between 0 and i (inclusive).

  3. Swap the values of the elements at j and i

  4. i = i - 1

  5. if (i > 0), go to Step-2

The algorithm has a time complexity of O(n).

2286 questions
0
votes
1 answer

While List isn't empty, remove a random element from List results in infinite loop

I am working on a simple shuffle script. I have a Generic method which takes as input a List and returns a List. The returned List should be shuffled. However, the code got stuck in an infinite loop, and I'm not sure why. Here is my…
JasperMW
  • 465
  • 3
  • 7
  • 22
0
votes
2 answers

Shuffle the list of Objects java stream

I have a list of words: List words The bean Word is: public class Word { private String name; private String meaning; ... } I would like to shuffle the elements to have the following: From: { name: "day", meaning: "giorno"}, { name:…
NikNik
  • 2,191
  • 2
  • 15
  • 34
0
votes
3 answers

How to shuffle letters in string with vowel isolated in Python

I am creating a function Takes input as a string. Returns a string. The return string will have the same number of words as the input string, and the same letters as the input string, but the individual words can be of different length. i.e.…
gummug
  • 13
  • 1
0
votes
2 answers

I tried using a fisher-yates shuffle for strings, but it didn't work

I tried shuffling a string with a fisher-yates shuffle, but although it properly gets the indexes and the values, it doesn't shuffle the string, what is wrong? globalVar = 'I am GLOBAL' function scrambler(anyString) { let placeHolder =…
JCaptain
  • 57
  • 4
0
votes
1 answer

Boolean does not returning from true to false

I have mp3 songs playing in listview. When I click shuffle button, its highlighting and stay focused colorful and this moment boolean became true. Then when I click again shuffle button, the highlight gone and this moment boolean should be false and…
alizulfuqar
  • 149
  • 1
  • 12
0
votes
4 answers

Trying to generate & display non-repeating random values for a BINGO game

I am working on making a bingo game. I've gotten as far as being able to get a random number generated and displayed at the click of a button. My only issue is that some values will end up being generated more than once. THAT IS THE PART I'M POSTING…
p4yner56
  • 17
  • 1
  • 1
  • 7
0
votes
1 answer

PHP array_rand shuffling issue with v5.2.10+

I've just recently updated my PHP to a newer version and have discovered that it's rendered some of my older, once functional code useless. Namely, since v5.2.10 with array_rand "the resulting array of keys is no longer shuffled" and therein lies…
Clarissa B
  • 239
  • 2
  • 5
  • 14
0
votes
1 answer

Directly shuffle iterable in Java

Is there a way to shuffle iterable directly without converting it to list in JAVA? Iterable all = Iterables.unmodifiableIterable( Iterables.concat(boy_agents,girl_agents)); Collections.shuffle(all); above…
Jack
  • 1,339
  • 1
  • 12
  • 31
0
votes
1 answer

How to apply php user session to random quote snippet?

Still learning PHP and trying to apply a user session snippet to my quote snippet so that it doesn't shuffle on every user page re-load. Here is the working session code being applied to a different random quote snippet: php - keep value that is…
Anonymous
  • 131
  • 5
0
votes
0 answers

Pytorch data loader shuffles example inside a batch

I have the following Dataloader that I am using for an autoencoder in Pytorch class DataLoader(data.DataLoader): def __init__(self, *args, **kwargs): super(DataLoader, self).__init__(*args, **kwargs) self.iterator =…
Maja
  • 151
  • 7
0
votes
1 answer

Reorganization DataFrame based on two columns

If I have a data frame that looks like this A B 0 a 0 1 a 0 2 a 1 3 a 1 4 a 2 5 a 2 6 b 0 7 b 0 8 b 1 9 b 1 10 b 2 11 b 2 12 c 0 13 c 0 14 c 1 15 c 1 16 c 2 17 c 2 Is there a…
Aran
  • 45
  • 5
0
votes
1 answer

Gridview in fragment giving a error when pass data to the adapter

listCountry = new ArrayList(); listFlag = new ArrayList(); listCountry.add("name"); listFlag.add("https://www.freepngimg.com/thumb/cartoon/4-2-cartoon-transparent.png"); listCountry.add("one"); …
Rover
  • 661
  • 2
  • 18
  • 39
0
votes
0 answers

How does calling random.shuffle on a h5py dataset work?

I've got a 150Gb h5py dataset I want to shuffle. In this post Shuffle HDF5 dataset using h5py the user said it took 11 minutes to shuffle a 30Gb data. However, I tried shuffling my dataset and it seemed to take an awful lot longer than 55 minutes…
Charlie
  • 176
  • 11
0
votes
1 answer

How can I sort posts in an shuffle mode in firebase, without repeat?

I want to show a list of the posts from a user following list. I can show it in the default order, but I want to show it in a shuffle order. I was using a function called shuffle, that works, but in my code doesn't work correctly, because repeat…
0
votes
2 answers

Trying to create a shuffle function

Function works but a 53rd undefined element gets added to the array when the number of shuffles gets too high. function shuffle(deck , shuffles) { for(let i = 0; i < shuffles; i++) { let first = Math.floor(Math.random() * 53); let…
Ggd Hhdhd
  • 145
  • 1
  • 8
1 2 3
99
100