shuffle

Fisher-Yates shuffle on a single string vs. using an equal length permutation?

寵の児 提交于 2019-12-22 14:01:31
问题 Right now I am working on a suite of word games as a means of teaching myself (and recreating some of my favorite word games!) With the help of an 'actual' studied programming friend, we have implemented a nice permutation method in one of my classes. It is finding all permutations from 3 letters and up and comparing them to Lists of strings I have containing what is essentially the Scrabble tournament word list. That's the background, here is my current issue: I now have all of the

How can I get all unique combinations of a word's characters?

我的未来我决定 提交于 2019-12-22 10:17:02
问题 I understand how str_shuffle() or shuffle works but I don't know it in this case. $word="tea"; I want to echo out all unique shuffling possibilities (tea, tae, eta, eat, ate, aet) 回答1: You need to produce all of the permutations of the string, either by iterating through the possibilities, or using a recursive method like this one below. Note that for a moderately sized array this will grow very large very quickly. For a word with unique characters, the number of possible permutations is n!

python random.shuffle's randomness

∥☆過路亽.° 提交于 2019-12-22 05:34:12
问题 Following is from python website, about random.shuffle(x[, random]) Shuffle the sequence x in place. The optional argument random is a 0-argument function returning a random float in [0.0, 1.0) ; by default, this is the function random() . Note that for even rather small len(x) , the total number of permutations of x is larger than the period of most random number generators; this implies that most permutations of a long sequence can never be generated. If I want to repeat getting a random

What’s the best way to shuffle an array in Perl?

[亡魂溺海] 提交于 2019-12-22 03:22:09
问题 So I have a file. Let’s say it looks like this (it's actually longer): 1234 2134 3124 4123 What is the best way to shuffle the lines in that file? 回答1: #!/usr/bin/env perl use strict; use warnings; use List::Util qw/shuffle/; my @arr = shuffle <>; print @arr; Usage : ./script file.txt 来源: https://stackoverflow.com/questions/13416337/what-s-the-best-way-to-shuffle-an-array-in-perl

What’s the best way to shuffle an array in Perl?

旧街凉风 提交于 2019-12-22 03:22:09
问题 So I have a file. Let’s say it looks like this (it's actually longer): 1234 2134 3124 4123 What is the best way to shuffle the lines in that file? 回答1: #!/usr/bin/env perl use strict; use warnings; use List::Util qw/shuffle/; my @arr = shuffle <>; print @arr; Usage : ./script file.txt 来源: https://stackoverflow.com/questions/13416337/what-s-the-best-way-to-shuffle-an-array-in-perl

Verify Knuth shuffle algorithm is as unbiased as possible

为君一笑 提交于 2019-12-21 17:57:05
问题 I'm implementing a Knuth shuffle for a C++ project I'm working on. I'm trying to get the most unbiased results from my shuffle (and I'm not an expert on (pseudo)random number generation). I just want to make sure this is the most unbiased shuffle implementation. draw_t is a byte type ( typedef 'd to unsigned char ). items is the count of items in the list. I've included the code for random::get( draw_t max ) below. for( draw_t pull_index = (items - 1); pull_index > 1; pull_index-- ) { draw_t

Select cells randomly from NumPy array - without replacement

。_饼干妹妹 提交于 2019-12-21 07:23:11
问题 I'm writing some modelling routines in NumPy that need to select cells randomly from a NumPy array and do some processing on them. All cells must be selected without replacement (as in, once a cell has been selected it can't be selected again, but all cells must be selected by the end). I'm transitioning from IDL where I can find a nice way to do this, but I assume that NumPy has a nice way to do this too. What would you suggest? Update: I should have stated that I'm trying to do this on 2D

How to use Java Collections.shuffle() on a Scala array?

十年热恋 提交于 2019-12-20 19:36:46
问题 I have an array that I want to permutate randomly. In Java, there is a method Collections.shuffle() that can shuffle the elements of a List randomly. It can be used on an array too: String[] array = new String[]{"a", "b", "c"}; // Shuffle the array; works because the list returned by Arrays.asList() is backed by the array Collections.shuffle(Arrays.asList(array)); I tried using this on a Scala array, but the Scala interpreter responds with a lengthy answer: scala> val a = Array("a", "b", "c")

Shuffling a poker deck in JavaScript with window.crypto.getRandomValues

☆樱花仙子☆ 提交于 2019-12-20 10:25:48
问题 A poker deck has 52 cards and thus 52! or roughly 2^226 possible permutations. Now I want to shuffle such a deck of cards perfectly, with truly random results and a uniform distribution, so that you can reach every single one of those possible permutations and each is equally likely to appear. Why is this actually necessary? For games, perhaps, you don't really need perfect randomness, unless there's money to be won. Apart from that, humans probably won't even perceive the "differences" in

How to shuffle a char array - JAVA? [closed]

假装没事ソ 提交于 2019-12-20 06:37:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I am not sure how to shuffle a char array using Java so could anyone help me, but please keep it really simple because I'm at GCSE level right now, Thank you. 回答1: Try using Collections.shuffle method like: Character[] myarray = ... List<Character> charList = Arrays.asList(myarray