Questions tagged [shuffle]

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

Filter by
Sorted by
Tagged with
11
votes
1answer
304 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 ...
10
votes
3answers
760 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
251 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
135 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
475 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
4k 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
1k 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
182 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
261 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. ...
6
votes
3answers
814 views

Is the way I'm handling deck (card) generation the wisest way to do it?

My Deck Class: (In case it isn't clear, a Card is just an object with two enums, one for suit and one for value). I'm ...
7
votes
4answers
8k views

Basic playing card generation and shuffle

This is my first attempt at Java so I appreciate any criticism or pointers. The program should generate a full set of given decks and then shuffle them. ...
14
votes
3answers
638 views

Allowing the user to alphabetize or randomize the contents of a text file

As a newbie programmer, I decided to try my hand at making a program whose function actually might be useful to someone, somewhere. This utility takes a text file, reads it out to the user, displays ...
7
votes
4answers
9k views

Shuffling function using rand()

I would like to hear your suggestions about my shuffling function in C++. I've decided to take advantage of using rand() to build a shuffling function. ...
6
votes
3answers
745 views

Follow up to Shuffling a list of track indices

This is the improved code to my last question: ...
9
votes
5answers
562 views

Shuffling a list of track indices

This question has a follow-up: Follow up to Shuffling a list of track indices I have a bunch of paths in an ArrayList<String> and when a user has activated ...
2
votes
1answer
126 views

Securely shuffling an array with 75 numbers in Go

I have a SHA512 hex string consisting of my random input and that of the user. Since rand.Seed only accepts a int64 I can never ...
3
votes
2answers
7k views

Shuffling array elements in C

This is an answer to this problem. Basically, given an array, swap the given number of elements in the array. The solution that came to my mind: since we always swap at least two elements, pick two ...
0
votes
1answer
306 views

Updating MySQL with shuffled numbers between 1 and 50

I need to assign a number to each userId. I think this is too much of a query for updating. Is it possible to reduce the number of queries, or is it okay? ...
15
votes
5answers
4k views

Shuffling a deck

My objective is to swap every element of a string array with a random element. ...
11
votes
3answers
7k views

Card shuffling with Fisher-Yates method

The code below takes a specified number of card decks, and shuffles them according to the Fisher-Yates method. Does this implementation have any bias? ...
10
votes
1answer
7k views

Fisher-Yates modern shuffle algorithm

I have implemented the shuffling algorithm of Fisher-Yates in C++, but I've stumbled across the modulo bias. Is this random number generation by rand() correct for ...
1
vote
1answer
164 views

Shuffling an array of cards

I have a deck of flashcards that I want to shuffle. Here's the method I'm using to shuffle them: ...
1
vote
1answer
92 views

Increase efficiency of card-ordering program

As mentioned in @rolfl comment. What this program does is that it "resequences the cards using a fixed system and count the number of times the resequencing happens before the output is the same as ...
4
votes
2answers
355 views

Review of reservoir sampling

I've been studying Reservoir sampling for a couple of days. What I've tried here is draw a uniformly random sample of size 3 from bigger data (the 26 characters of the English alphabet) via reservoir ...
5
votes
1answer
179 views

Pile shuffle of a vector

My goal is to simulate a Pile shuffle of a vector. It takes 2 optional arguments for the number of piles to use and how many times to perform the shuffle. As this is my first attempt at clojure code, ...
5
votes
2answers
4k views

Fisher-Yates shuffle algorithm in javascript, modern and inside-out versions

I've implemented two different versions of the Fisher-Yates shuffle in javascript, and I'd like to know if I've made any mistakes. I'm creating a deck of playing cards. I'm interested in these ...
5
votes
2answers
894 views

Human (imperfect) array (card) shuffle written in C

I've got this humanoid_shuffle I wrote in Python. I've been wanting to learn C so as an exercise I ported it to C. As this is my first venture into C and even the ...
3
votes
1answer
472 views

JavaScript shuffle idea

Based on the standard implementation of Array.sort in JavaScript, would the following be a reasonable way of shuffling the contents of an array? Is it moderately ...
4
votes
1answer
1k views

Activating items in some randomized arrays

I've got a list with about 120 items in IE and I have some items I want to activate. I compare, build and randomize some Arrays on the fly. The for loop in the run()...
3
votes
1answer
3k views

Shuffling a JSON array in Java

Since I did not get a satisfactory answer here (and I really needed to get it going on this weekend), I decided to implement my own Fisher–Yates shuffle, porting the code I found in other SO posts. I ...
19
votes
3answers
2k views

Shuffling algorithm for a “guess that tune” game

I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order: ...