Questions tagged [shuffle]

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

Filter by
Sorted by
Tagged with
9 votes
1 answer
1k views

Card Shuffle without using any help C#

I'm new to C# but not 100% new to development. I wanted to try writing a Card Shuffle + Card Dealing algorithm using as least as possible inbuilt functions or any libraries and no internet use to ...
  • 101
3 votes
1 answer
87 views

Improving performance of 'Prioritized left shuffle algorithm'

I wrote a prioritized left shuffle algorithm (the code is copied from my open source C# project Fluent Random Picker). That means: You've got some values and each of them has a priority (a number). ...
  • 207
0 votes
1 answer
334 views

Fisher Yates Shuffle, but using Javascript Array Functions

I have been looking at the Fisher Yates randomizing suggestions on StackOverflow after ruling out arr.sort(v => Math.random() - 0.5) due to lack of randomness in ...
  • 115
9 votes
2 answers
579 views

Daily stand-up list

Like most teams, we take turns to speak in our daily stand-ups. When we gather around the sprint board, it's easy to know who speaks when - we start at one end and pass the role along the line. At ...
  • 60.7k
7 votes
3 answers
100 views

Out of N number of participants, draw out M winners

It could be a simple Fisher-Yates, but then if the number of participants is 1,000,000 and the number of winner is only 3, then we really don't need to shuffle the whole 1,000,000 numbers, so the ...
1 vote
0 answers
29 views

Implementation of GNU shuf(1) now supporting nul characters

Some time ago, I implemented shuf(1), but it had an issue: it ignored nul characters in the input. This new version tries to solve this problem (but uses the ...
  • 854
3 votes
1 answer
102 views

POSIX + BSD-extensions implementation of shuf(1)

I implemented GNU shuf(1) in C using POSIX system calls and some BSD extensions. You must compile it with -lbsd. ...
  • 854
2 votes
2 answers
103 views

Is this a reasonable algorithm for shuffling cards?

So I based my "algorithm" on the poke method defined by Persi Diaconis. You start with the card at the bottom of a given deck and then poke the top card into a random position in the deck. At first ...
3 votes
1 answer
447 views

Fisher-Yates shuffle in Haskell

This is the Haskell version of my recursive Fisher-Yates shuffle in JS. ...
  • 777
3 votes
2 answers
118 views

A basic trivia app

The app grabs 10 questions from an API, displays them one by one with 4 multiple choice answers. These answers are clickable buttons that alert to whether the answer is correct or not. Finally the ...
12 votes
5 answers
5k views

Deck of cards with shuffle and sort functionality

Going through Head First C#'s Chapter 8: Enums and Collections, I learned about List<T>, as well as IComparable<T> ...
  • 20.3k
2 votes
2 answers
270 views

Sudoku generator using seed Sudoku

I have created a Sudoku generator in Java. Here I am using a basic solved sudoku as seed and by transposing it and shuffling its row and columns I get a new solved sudoku. ...
2 votes
1 answer
304 views

Game to shuffle and guess a word

I'm new to C++ and while learning, I wrote a simple program that asks for a word, shuffle sthe characters and then asks another person to find the original word, given the shuffled letters. I would ...
  • 375
5 votes
3 answers
542 views

Confuse a text without making it unreadable

Scientists have found that a text can still be read even if only the first and last letter of a word are in their right place. The remaining characters within the word can be arranged randomly. ...
's user avatar
2 votes
1 answer
2k views

Shuffle deck of cards in JavaScript

I know randomness in programming can be a deep topic, and searching the topic seems to result in Fisher-Yates being the best method, but I'm curious what people would say about this method. Basically,...
  • 461
2 votes
2 answers
126 views

Shuffle array elements by rearranging the key value associations

PHP's shuffle() function destroys the array keys, so I decided to write a shuffle function that doesn't do that and instead rearranges key-value associations. As I ...
  • 1,796
2 votes
2 answers
82 views

Return Set<Integer> with random unique Integer numbers between min and max range

I need set of random unique Integer numbers for my unit test. I implemented this method, however I'm not sure if this is best way to implement this. ...
  • 123
1 vote
1 answer
415 views

Fisher-Yates shuffle Java implementation

This is my attempt at an implementation of the modern Fisher-Yates shuffle in Java. I'm not sure if it can be made more efficient, but I did my best to make it as simple as possible, and I learned how ...
  • 161
7 votes
4 answers
4k views

Selecting random elements from a `IList` with no repetitions

Description This is a utility algorithm that selects a number of elements from a source list without repeating elements. Background My use case is creating a random path for a NPC that has to ...
  • 3,473
5 votes
4 answers
10k views

Cards shuffling and dealing program

The program interacts between cards and four players among whom cards are to be distributed. The Program do the following function Creates a deck of cards. Shuffle the deck. Shows the deck. Deal ...
  • 105
2 votes
2 answers
56 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
1 answer
289 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, ...
  • 185
1 vote
2 answers
134 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 ...
1 vote
1 answer
683 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 ...
  • 193
1 vote
2 answers
111 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? ...
  • 125
7 votes
3 answers
3k 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 ...
  • 440
1 vote
1 answer
166 views

ShuffleBag (Fisher-Yates + PcgRandom)

Anything that could be done better here? ...
  • 1,840
4 votes
1 answer
109 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 ...
  • 41
3 votes
1 answer
518 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 ...
  • 341
5 votes
1 answer
99 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
3 answers
457 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. ...
  • 123
3 votes
1 answer
198 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. ...
13 votes
3 answers
9k 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 ...
  • 293
4 votes
2 answers
2k 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
0 answers
391 views

Seeded array shuffle

This should be relatively simple, but I want to know if I've done the randomness bit correctly. ...
11 votes
4 answers
2k 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.1k
32 votes
9 answers
12k 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 ...
  • 421
3 votes
2 answers
264 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 ...
  • 31
5 votes
2 answers
364 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. ...
  • 153
2 votes
3 answers
5k 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,443
4 votes
2 answers
2k 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 ...
  • 360
1 vote
2 answers
91 views

Shuffle data simulation

Is the following procedure good for shuffling data in general (not just for JavaScript)? ...
  • 129
4 votes
2 answers
2k 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 ...
  • 177
1 vote
2 answers
48 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
5 answers
719 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 ...
  • 409
3 votes
2 answers
3k 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
2 answers
4k views

Fisher–Yates shuffle in C#

Is this a proper C# implementation of the Fisher–Yates shuffle? ...
  • 5,930
4 votes
1 answer
2k 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 ...
  • 686
8 votes
7 answers
15k 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? ...
  • 215
3 votes
1 answer
2k 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 ...
  • 133