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

IEnumerable shuffling not random for set of set

I am using shuffling methods from my previous question- An extension method on IEnumerable needed for shuffling But when I am using any of these methods for shuffling each elements of an IEnumerable> by calling something…
Gulshan
  • 3,611
  • 5
  • 35
  • 46
0
votes
1 answer

Is mask adaptive in __shfl_up_sync call?

Basically, it is a materialized version of this post. Suppose a warp need to process 4 objects(say, pixels in image), each 8 lanes are grouped together to process one object: Now I need do internal shuffle operations during processing one…
Finley
  • 795
  • 1
  • 8
  • 26
0
votes
0 answers

String repeating problem in shuffle in php

So i want a little team lottery system. All teams playing all team. No repeating! So, i have got a code.
0
votes
4 answers

Shuffling Deck of Cards Using Card object

Have been attempting to create a class called CardDeck to shuffle card objects created in a different class (called DeckOfCard, sorry for the confusion, not well named) but have run out of ideas of how to accomplish this. here is what I have come up…
chloe
  • 33
  • 1
  • 4
0
votes
2 answers

Shuffling a dataframe in R with no repeats

Would anyone happen to know how to script a shuffle of a dataset in R, such that if I have 25 numbers (5 rows x 5 columns) in a dataframe, and I shuffle 25 separate times, each number appears in each location exactly one time? Thus it's not…
chazmatazz
  • 133
  • 1
  • 9
0
votes
0 answers

Unreliable randomizing or loading of images

I want to randomly display some images stored as attributes on an entity "Disc" in Core Data. I've been using the Swift Array.shuffled() function performed on the fetchedObjects of my NSFetchedResultsController "thisFRC." First problem was that the…
rattletrap99
  • 1,469
  • 2
  • 17
  • 36
0
votes
3 answers

How to really shuffle sequence in Clojure?

(defn shuffle-letters [word] (let [letters (clojure.string/split word #"") shuffled-letters (shuffle letters)] (clojure.string/join "" shuffled-letters))) But if you put in "test" you can get "test" back sometimes. How to modify the…
ivitek
  • 11
  • 2
0
votes
1 answer

Collections.shuffle doesn't work as expected with SimClock Random value

I would like to add some random behavior to my code. I want to do it with the timestamp value. By this way, I want to shuffle a list with the current timestamp. This is my code: Random random = new…
Miguel.G
  • 377
  • 1
  • 6
  • 20
0
votes
2 answers

Twig: How to write a for loop with an integrated if condition based on a value

the situation I have a little symfony twig app, where I run a for loop to get all items shown. I want to let the user decide if his content is rendered in a specific order or randomly, for which I will use the twig extension function shuffle(). If…
Mista K.
  • 105
  • 9
0
votes
2 answers

Is there a better method to recursively execute the shuffle method without exceeding the maximum call stack for large arrays?

I'm trying to write a RECURSIVE function that randomizes/shuffles an array. The function I have written is using the Fisher-Yates shuffle method, which works fine on small arrays, but gives a 'Maximum call stack exceeded error' on my intended array…
George
  • 147
  • 2
  • 12
0
votes
2 answers

How to take sample from two columns of R data frame jointly?

I have a data frame with 4 columns. I am trying to shuffle two columns of the data frame together such that those two columns are always related. I have tried 'sample' function, but it it limited to one column of data frame only. data =…
0
votes
0 answers

PHP array - appending number (value) to string (key) for each element

I have an array like $a = array ( "Leafs", "Sabres", "Red Wings", "Flyers" ); that I shuffle shuffle($a); The resultant array could be: Array ( [0] => Sabres [1] => Red Wings [2] =>…
machump
  • 1,207
  • 2
  • 20
  • 41
0
votes
1 answer

How does Polkadot's VRF achieve randomness to shuffle validators?

Contrary to Ethereum which uses RANDAO (possibly enhanced with VDF), in Polkadot, a verifiable random function (VRF) is used to shuffle validators and select potential block proposers for certain slots. Where does the randomness come from, i.e. how…
Swader
  • 11,387
  • 14
  • 50
  • 84
0
votes
3 answers

How to Shuffle two Objects in javascript which has an Id and value in it

Well i been doing some research on it i have one Object in javascript and i have made copy of it i have to shuffle both the objects data's. I dont want both the objects in same order. I need to shuffle it. I have shuffled it in different manner…
0
votes
5 answers

How to get a certain number of unique random numbers in a certain range?

I have a function that takes user input to tell it how many random numbers to output, and the range to make the random numbers between (say 1-90). The problem is that it will give repeat numbers, but I want only unique numbers. Does anyone know how…
fitz2882
  • 1
  • 2
1 2 3
99
100