Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shuffle]

Shuffling is the act of randomizing the order of the elements in a collection.

2
votes
2answers
46 views

Continuous Shuffler with “linked loop”

As an academic exercise, I decided to implement a continuous shuffler, as seen on casino blackjack tables. It operates by storing a "linked loop" (a linked list with the last element linked to the ...
1
vote
1answer
47 views

Shuffling sections of an ordered list based on tuple values

I have a list as follows and I want to shuffle the elements that have the same frequency while keeping the elements with different frequencies in the correct positions. The code below works; however, ...
1
vote
2answers
45 views

Fisher-Yates Shuffle

This is a cut-and-dried Fisher-Yates implementation. As not typically a JS developer, I've tried to incorporate as many best practices as I can. I would appreciate any input as to make it conform to ...
0
votes
1answer
59 views

Shuffle a string in a repeatable way

The following function is designed to accept a string of characters and an integer. The function returns a string that's a reordered version of the original string. The reordering process is ...
1
vote
2answers
90 views

Randomly generate set of size M from array of size N

The following algorithm attempts to randomly generate a set of size M from an array of size N. It is not based on Knuth Fisher Yates shuffle, but could someone verify its correctness? ...
5
votes
3answers
193 views

Shuffling an array keeping some elements fixed

The task is simple to understand: how to shuffle an array keeping some elements fixed. Let us take an example: starting from the array [1, 2, 'A', 3, 'B']. Having ...
0
votes
0answers
53 views

ShuffleBag (Fisher-Yates + PcgRandom)

Anything that could be done better here? ...
4
votes
1answer
47 views

Generate another random path through a complete graph

What this does is generate a random path of cities to later calculate the length of the newly generated tour of cities, the TSP. I am trying to figure out if there is a more efficient way to write ...
3
votes
1answer
140 views

Secret Santa - Pick Pairs

Interested to hear your thoughts on this Secret Santa pairs picker. It's pretty standard but I'll explain the rules all the same: All names go into a hat Each person picks a name from the hat and ...
2
votes
1answer
66 views

getRandom() - Randomize array and get result

I've written a function that allows you to pass an array of values, which is then shuffled and returned based on a parameter $preserveArray. This is the code: <...
1
vote
3answers
165 views

Deck Shuffling Method

Just wondering if you guys think this is a good way to shuffle a deck or a bad way. Updated to show the GetRandom function as requested. ...
3
votes
1answer
131 views

Fisher-Yates shuffle in JavaScript

This is my first time making a function just from reading about it on Wikipedia, so I'm sure there's room for a lot of improvement. ...
12
votes
3answers
4k views

Python shuffle the middle letters in all the words of a sentence

The purpose of the program is to shuffle only the middle letters of each word in a sentence, leaving it still readable like this: Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't ...
4
votes
2answers
277 views

Creating multiple files from a list

This piece of code is to get random samples from two String lists, pos and neg. Based on a ...
1
vote
0answers
167 views

Seeded array shuffle

This should be relatively simple, but I want to know if I've done the randomness bit correctly. ...
10
votes
4answers
889 views

random_iterator in C++

This is a small utility that permutes a C++ standard container without modifying the container being iterated: random_iterator.hpp ...
26
votes
9answers
7k views

Generate a list of 10,000 numbers in random order

I am in the middle of an interview process with a company I am very excited about. The position is for a Junior Developer for C# applications. I have a year of experience at my current position as ...
3
votes
2answers
145 views

Shuffling chunks of ints in an array

The shuffle method in ShuffleMethods.java takes an array of ints and shuffles them by chunks of ints in another array. So for example, if we had an array of ints ...
5
votes
2answers
175 views

Helper method to shuffle cards list for online gaming

I have written this code to shuffle a deck of cards. I would like to hear your inputs. ...
1
vote
3answers
2k views

Two ways to randomly shuffle cards

Here are two implementations I wrote to randomly shuffle cards. The first method (shuffle) selects a random card, then swaps it to the front. The second method (<...
3
votes
3answers
189 views

Display four random entries from an array

This code will take the array shown and display 4 random entries in the format shown (or near enough). Are there any parts of this that can be optimised? I'm not happy about the ...
1
vote
2answers
68 views

Shuffle data simulation

Is the following procedure good for shuffling data in general (not just for JavaScript)? ...
3
votes
2answers
679 views

Deck shuffle and drawing cards

I developed a simple deck shuffle and drawing system, as a test on how to use collections and learn from it. However, I think my code is a bit wonky, and I think here is the best place to get new ...
1
vote
2answers
32 views

Shuffling many collections by folding over a numeric range

Often, I find myself folding over a range object if I need to repeatedly transform something. This, to me though, feels like an abuse of ...
5
votes
5answers
600 views

Shuffles male or females names based on Fisher Yates algorthim

The code below has many Lists<> but I'm not sure how to modify it. The only thing here that is an algorithm is the Fisher Yates shuffle algorithm. I am trying ...
2
votes
2answers
1k views

Generating random numbers and decks of cards

So I have some code here: First a simple random # generator and a array-choosing function: ...
2
votes
2answers
1k views

Fisher–Yates shuffle in C#

Is this a proper C# implementation of the Fisher–Yates shuffle? ...
4
votes
1answer
857 views

Tetris random piece generator

I was inspired by this Reddit /r/dailyprogrammer challenge: Contrary to popular belief, the tetromino pieces you are given in a game of Tetris are not randomly selected. Instead, all seven pieces ...
7
votes
7answers
6k views

C# Card Shuffle

So, I took a stab at the ole C# Card Shuffle. I wanted to create my own genuine solution rather than copy someone else's. Any advice? ...
2
votes
1answer
1k views

csvshuf: a tool to shuffle CSV columns written in Python

Edit: After reading Gareth's answer I have pushed an updated version of the code to github. I needed to shuffle cells from specific columns in several CSV files. One of the requirements was to be ...
2
votes
0answers
40 views

Generate sample of permuted sequences with non-repeating elements

I have a very long sequence of letters (>20000 elements long). I want to permute them so that I have another sequence using the same letters but in a different order but still with the property of no ...
0
votes
1answer
301 views

Shuffle array without duplicates

I made a function about random backgrounds And those images will unique as possible. (Shuffle again after all gone) My steps is : Setup the array Shuffle it Do function (check if ...
11
votes
1answer
548 views

Corrupting Java arithmetic through reflection

Inspired by a PPCG answer, I wrote this code, which shuffles the autoboxing caches of Number subclasses. This leads to, among other things, outputting ...
2
votes
1answer
59 views

Comparing two shuffling methods

I'm trying to randomly shuffle an collection of integers within a List and I have came up with two shuffling method that does the job. However, I'm not sure which ...
1
vote
2answers
4k views

Logic for shuffling sliding puzzle

I'm working on a sliding puzzle, one little project as a hobby, and yesterday I thought that instead of working on an algorithm to figure out a solved puzzle, it would be easier to make an algorithm ...
2
votes
1answer
1k views

Round Robin Tournament

RoundRobin is an implementation of the Round-robin style tournament: ...
1
vote
1answer
42 views

Create a collection of binaries with random set positions

I would like to create a collection of binaries with n set bits and total length should be between n and 31; also those set bits ...
5
votes
1answer
396 views

Shuffle a deck of cards, using the overhand shuffle method

I've started learning Clojure, after many years of Java. As one of a series of exercises, I'm writing a simple card game, and the overhand-shuffle function is shown ...
6
votes
3answers
151 views

Simple word shuffling game - follow-up

From my previous question, I got great feedback which helped improve my code which I submitted. I went back and built upon that and came back to see if my code is an improvement. ...
11
votes
1answer
264 views

Secret Santa with Groups on Swift

I am working on an special version of Secret Santa with internal sub-groups. Typical Secret Santa (SS) requirements: Cannot be assigned to themselves Should be random Every participant should be ...
9
votes
3answers
416 views

Simple word shuffling game

I have made a game (I like to code when in my spare time) where words are taken at random from a list and displayed on a label. If they type it correctly, their ...
7
votes
2answers
234 views

Reading lines from a file in random order

I originally wrote this as an answer to a question on Stack Overflow, but it turned out so nicely that I decided to post it here to see if I can make it even better. ...
6
votes
1answer
109 views

Forth to the past - qsort

To make a long story short, I must revive my Forth. It is rusty; last time I did anything serious in Forth was 30 years ago (man, I am old). As an exercise, I translated an STL-like implementation of <...
6
votes
1answer
343 views

Shuffling an arbitrary list or sequence

After reading this question I wanted to write a short example of how a list or sequence could be shuffled in .net. The result turned out to not be very short: Program.cs ...
0
votes
2answers
2k views

Shuffle Symfony entities

I've got an object $contest which is a Symfony entity that has some other entities assigned. I can get them by ...
6
votes
4answers
2k views

Given N, generate sequence of random numbers from 0 to N - 1 with no repetitions

Problem statement: Given an integer n, write a function to return an array of size n, containing each of the numbers from 0 to n-1 in a random order. The numbers may not repeat and each number must ...
6
votes
3answers
980 views

Shuffle a sorted array so that left portions contains even indices and right portion contains odd indices numbers

I have been solving the following problem: Input array: \$[7,4,2,5,1,9,6]\$ Output array: \$[1,4,6,9,7,5,2]\$ I tried to do it in the following way: Sort the array. So, Input array becomes \$[1,2,...
0
votes
2answers
173 views

Three Cards Trick - Assigning random number to the cards

At first I have three cards like this: ___ ___ ___ | | | | | | | A | | A | | Q | |___| |___| |___| and then I shuffle them to this: ...
6
votes
1answer
216 views

Fisher-Yates shuffle in Scheme

There are many ways to shuffle lists; for example, Racket's built-in shuffle assigns each list element with a random number as a sort key, then sorts the list, ...
3
votes
2answers
4k views

Shuffle the elements of the array randomly

I have written the code to shuffle the elements of the array. Please let me know of any loopholes in the written code. ...