FAQ Database Discussion Community


how can i shuffle the lines of a file by chunks of 100 lines with Unix command line tools?

unix,shuffle
I have a large text file and I want to shuffle the file by chunks of 100 lines. So the order within each chunk of 100 lines is preserved. Is there anyway to accomplish this with only Unix command line tools?

Shuffle given array

php,arrays,search,shuffle,tag-cloud
I have this tag cloud, which is currently set to show the most popular item first with the use of (line 205): // arsort($array_end); which reverses the array. If i leave this out it shows the list alphabetically. I would like to have the results shown randomly. I thought of...

Randomize an array while leaving specific elements in place?

c#,arrays,random,shuffle
Quick question, something in my logic here isn't adding up. Basically I want to shuffle or randomize an array, but keep specific elements in place. Anything over 900 should stay in the same position. This looks like it should work, but apparently I'm missing something. public static int[] ShuffleArray(int[] data)...

card game in c, shuffle linked list

c,linked-list,shuffle,realloc
I trying to shuffle a linked list in c. My idea was to move the list into an array of card then to shuffle the array and then to put it all back in the linked list. when I do build everything is ok but when id use the debugger...

Shuffle array except for the first three elements

php,arrays,shuffle
I have an array in PHP: Array ( [0] => Red [1] => Green [2] => Blue [3] => Yellow [4] => Purple [5] => Orange [6] => Brown ) I want this array to be shuffled except for the first three elements ([0][1][2] should stay on the same position)....

random_shuffle modifies shuffled objects (c++11)

c++,algorithm,c++11,shuffle
I have a vector with Tour objects and want to shuffle them. Fortunate there is a function random_shuffle(). I print the objects before and after the shuffling, however, one field of the objects is not shuffled at all. The first thing to come to mind is that the copy or...

Is it bad (or even dangerous) to random_shuffle vector of shared_ptrs?

c++,vector,shared-ptr,smart-pointers,shuffle
using namespace std; vector< shared_ptr<MyObject> > objects; // objects gets filled in by something random_shuffle(objects.begin(), objects.end()); Is this bad or inefficient for any reason? Is there a better way of doing it? (I want my array of smart pointers sorted randomly) EDIT: I'm asking because there are going to be...

Shuffle out a specific object from array

java,arrays,object,shuffle
I have an array storing different mammals, the objects stored in the mammals array are such as dogs, cats etc which I've created with this code: Mammals obj = new Cats(); Mammals obj = new Dogs(); etc.... Now I want to shuffle out a specific object from the array, just...

Good way to shuffle lines in a textfile with DataFlow

shuffle,google-cloud-dataflow
I have a very long text file (few hundred GB) I'd like to shuffle the lines of. I'm wondering if there is a good way to do this with DataFlow. I imagine I would get a small shuffle if I just put the file in and had a ParDo that...

Import a text file, shuffle the contents, display on screen

python,import,shuffle
I have a list of team names in a txt file. I want to open the list, shuffle the names then display the result on the screen. Have tried the code below with little success. def shuffle2(): with open("teams.txt", mode="r", encoding="utf-8") as myFile: lines = random.shuffle(myFile.readline()) print(lines) ...

Error 'no match for call to vector normal_iterator >::difference_type)'

c++,vector,iterator,shuffle
I'm trying to use this vector.h function: random_shuffle(s.begin()+from+i,s.begin()+to,s); This error happens: c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_algo.h|5255|error: no match for call to '(std::vector<int>) (__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'| Any idea? Thank in advance!...

What is a good explanation of how a card shuffling program works?

c,arrays,shuffle
I am trying to get a better understanding of how the below program works. The program is designed to shuffle a deck of cards in a random order. Could someone explain some of the details of the functions and how exactly the code works? I understand the use of the...

Shuffle instruction in CUDA

c++,cuda,shuffle
I am new to cuda so maybe this will be noob question, but here we go... I can't use shuffle instructions in my kernel and I don't know why. I have Quadro K620 with compute capability 5.0, but instruction such as __shfl_down aren't recognized. I am using Visual Studio 2013....

How do I store an array of strings into another array of strings?

c#,arrays,string,shuffle
I'm trying to store my old array of struct type that holds first names of people into a new string array that has been downsized so I can then shuffle it round in another method. string[] newStringArray = new string[10] for (int i = 0; i < oldStringArray.Length; i++) {...

Shuffling list of widgets? Tkinter

python,json,tkinter,widget,shuffle
Finally I have finished this damn thing! Except for one issue. I have a program quiz program created with tkinter that grabs a dictionary from a list inside a JSON file. Now everything appears to be working fine, except for the shuffling of a list of buttons which remain in...

Randomly shuffle a weighted array

ruby,arrays,shuffle
There is a hash with IDs and weights of these IDs. y = { 1 => 0.7, 2 => 0.2, 3 => 0.1 } I would like to shuffle this hash according to the weights. I tried a number of different ways, all of which give me similar, unexpected results....

storing 13 random values without duplicates from a string array in java

java,android,random,unique,shuffle
I want distribute 13 values to a string without duplication. i have used random function and shuffle as well but it is giving me 1 value from this String array String[] orgCards = { "ca", "ck", "cq", "cj", "c10", "c9", "c8", "c7", "c6", "c5", "c4", "c3", "c2", "sa", "sk", "sq",...

Modify program to encrypt both uppercase and lowercase input

c++,encryption,random,shuffle,alphabet
I have to write code for a random cipher problem. I have done it, but the program transforms only uppercase or lowercase (depending on what I choose) letters as input. What should I change so that the program transforms both upper and lower-case letters? code: srand(time(0)); //seed for rand() static...

Adding a shuffle to a WMPlib playlist

c#,media-player,shuffle
I'm having trouble adding a shuffle to the code below. Could someone please help me? All I need is it to shuffle the items in playlist randomly after they've been added. WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer(); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo( @"C:\Users\Callum\Music\ItunesMusic\"); System.IO.FileInfo[] files = dir.GetFiles(); WMPLib.IWMPPlaylist playlist = wplayer.playlistCollection.newPlaylist("myplaylist");...

Is there a way to remove two numbers not affecting others?

php,arrays,shuffle
The code is giving the following output and each time, it will give a different output. Is there any way to remove to 2 numbers for example 15 and 60, so that other numbers are not effected they remain the same? I have tried but could not get the desired...

How to configure java memory heap space for hadoop mapreduce?

java,hadoop,mapreduce,heap,shuffle
I've tried to run a mapreduce job on about 20 GB data, and I got an error on reduce shuffle phase. It says that because of memory heap space. Then, I've read on many source, that I have to decrease the mapreduce.reduce.shuffle.input.buffer.percent property on mapred-site.xml with the default value 0,7....

Perfect shuffle and unshuffle, with no auxiliary array

c++,algorithm,shuffle
Before any concrete question, please note that my goal is not to shuffle randomly the array, but to perform a perfect shuffle as the one a ideal dealer may do with a set of cards, that is, splitting the deck in half and performing one shuffle passage (interleaving a card...

Ruby - Delete number from random array and return array with n random numbers?

ruby,arrays,random,shuffle,pop
I want to make one method in ruby which returns one random number from an array and made this: @nr = 1..60 def ar_one ar = @nr.to_a.shuffle ar.pop end But i get the numbers more than one time and the array is never nil. Whats wrong with this? And I...

Java: Shuffle a Deck of 32 cards?

java,methods,shuffle
I've wrote this method on my own I want to know if there is a better way to do it? public Card[] Shuffle(){ for(int i = 0; i < Deck.length; i++){ int x = i + (int) (Math.random() * (32 - i)); Card temp = Deck[i]; Deck[i] = Deck[x]; Deck[x]...

Global scope for array of structs inside function - Swift

arrays,function,swift,struct,shuffle
I would like to shuffle my array questions and use the shuffled array in the program when it starts. I have created this function that shuffles the array. func shuffleQuestions() { var shuffledQuestions = shuffle(questions) } This gives me an array with questions shuffled that inherits the values from the...

Combining jQuery code - ImagesLoaded + Shuffle.js

jquery,merge,shuffle,imagesloaded
My goal is to put the setupSorting function inside of the ImageLoad function. They work when separated (here), but sorting fails when combined (here). This: $(document).ready (function(){ /* reshuffle when user clicks a filter item */ $('.filter-tags a').click(function (e) { e.preventDefault(); // set active class $('.filter-tags a').removeClass('active'); $(this).addClass('active'); // get...

Python: How to track “correct” answer in randomized multiple choice

python,python-2.7,random,shuffle
I successfully built a function to prompt the user with a question, followed by randomly ordered answer choices. However, since the answer choices are now randomized, how will python recognize the user input (a number: 1, 2, 3, or 4) for the "correct" answer? import random def answers(): answerList =...

Cannot find symbols/variables for Pack class, solution?

java,arrays,oop,shuffle
This is probably something incredably simple it will annoy me completely, but admitidly I'm stuck. I am close to finishing an assignment, but I am hitting a dead end due to the system not being able to find any symbols in this class, refered to as the Pack class. I...

PHP Shuffle Include(ed) Files

php,include,shuffle,php-include
I'm trying to use SHUFFLE function to show FILE1.php or FILE2.php at random. Here is my code: <?php $banner1 = include 'file1.php'; $banner2 = include 'file2.php'; $banners = array( $banner1, $banner2); shuffle($banners); print $banners[0] ?> The problem I have - if instead of doing include 'file1.php'; i just use text...

mapreduce.reduce.shuffle.memory.limit.percent, mapreduce.reduce.shuffle.input.buffer.percent and mapreduce.reduce.shuffle.merge.percent

java,hadoop,mapreduce,shuffle
I just want to verify my understanding about these parameters and their relationship, if I am wrong then please notify me. mapreduce.reduce.shuffle.input.buffer.percent tells total amount of memory allocated to entire shuffle phase of a reducer. mapreduce.reduce.shuffle.memory.limit.percent tell maximum percentage of the in-memory limit that a single shuffle can consume from...

Shuffle element such that, no element should come at its original index

c#,algorithm,random,permutation,shuffle
I have a list of Object elements SourceList ResultList (Expected) Obj_A Obj_F Obj_B Obj_C Obj_C Obj_G Obj_D Obj_B Obj_E Obj_A Obj_F Obj_B Obj_G Obj_E Shuffle elements in SourceList such that, no element should come at its original index(in SourceList) in ResultList. For Example, in SourceList C is at index 2,...

Shuffle two lists in the same order in python

python,shuffle,psychopy
I have a question about shuffling, but first, here is my code: from psychopy import visual, event, gui import random, os from random import shuffle from PIL import Image import glob a = glob.glob("DDtest/targetimagelist1/*") b = glob.glob("DDtest/distractorimagelist1/*") target = a distractor = b pos1 = [-.05,-.05] pos2 = [.05, .05]...

shuffle() doesn't work as expected with an associative array

php,arrays,associative-array,shuffle
I want to do a quiz and here is my array: $questions = array("1+1"=>2,"5+2"=>7,"5+9"=>14,"3+5"=>8,"4+6"=>10,"1+8"=>9,"2+7"=>9, "6+7"=>13,"9+3"=>12,"8+2"=>10,"5+5"=>10,"6+8"=>14,"9+4"=>13,"7+8"=>15, "8+9"=>17,"4+8"=>12,"7+1"=>8,"6+3"=>9,"2+5"=>7,"3+4"=>7); shuffle($questions); foreach($questions as $key => $value) { echo $key.' '; } However, from the above code, I get the output like the following: 0 1 2 3 4 5 6 7 8 9 10...

Having problems with python's random.shuffle

python,matrix,random,permutation,shuffle
I would like to make a matrix whose lines are different permutations of the following vector= [1,2,3,4,5,10,10,10,10,10] I tried to use the random.shuffle function, but it seems that everytime I use that, It redefines all objects to which it is assigned. For example, I have tried the following: vec=[1,2,3,4,5] for...

Choosing k out of n

algorithm,shuffle
I want to choose k elements uniformly at random out of a possible n without choosing the same number twice. There are two trivial approaches to this. Make a list of all n possibilities. Shuffle them (you don't need to shuffle all n numbers just k of them by performing...

Shuffling an array

c,arrays,random,shuffle
What this code is supposed to do is shuffle an array, nonetheless every time I run it on a I get the same "shuffled" array (of course by inputting the same un-shuffled array) I thought the srand(time(NULL)); part was going to make sure of that. If that is not it...

ruby koans shuffle what is happening

ruby-on-rails,ruby,shuffle
Can't figure out this one of the ruby koans. Maybe someone could help?The answers you seek... undefined methodto_a_shuffle' for 1..5:Range Please meditate on the following code: /Users/nicholaskelly/koans/koans/about_dice_project.rb:12:in roll' /Users/nicholaskelly/koans/koans/about_dice_project.rb:24:intest_rolling_the_dice_returns_a_set_of_integers_between_1_and_6'` and here is about_dice_project.rb12: @values = (1..number).to_a_shuffle ...

How to Shuffle/Deal a deck of cards in GUI

java,user-interface,war,shuffle
Hello everyone I am currently making a GUI. It is going to be the card game called war what I am trying to do is split the deck randomly between the user and the computer. I have made three arrays one for you computer and the full deck and I...

Default_random_engine passed into a function gives repeatable results

c++,c++11,random,shuffle
I have a class Permutation that inherits from std::vector<int>. I created a constructor that makes the object filled with non-repeating numbers. Randomness is meant to be guaranteed by <random> stuff, so the declaration goes like this: /* Creates a random permutation of a given length * Input: n - length...

Shuffle instruction in CUDA not working

c++,multithreading,cuda,shuffle
I have got problem with shuffle instruction in CUDA 5.0. This is snippet of my kernel. It is inside the loop. Print is there only for debug purpose because I can't use ordinary debugger: ... tex_val = tex2D(srcTexRef, threadIdx.x + w, y_pos); if (threadIdx.x == 0) { left = left_value[y_pos];...

how to shuffle a php array but keep the index in foreach

php,arrays,foreach,shuffle
i have an array and its data are displayed in a grid using a foreach loop. the index of the foreach is used as part of url for each entry in the grid. $i=0; foreach ($array as $grid) { $name = $grid->name; $address = $grid->address; echo '<li> <a href="javascript:myclick('.$i.');" title="">'...

Array_map when elements are shuffled

php,shuffle,array-map
I have this array (it's just a part of it). 6 = question ID, optionIDs = possible answers. Array ( [3] => Array ( [0] => 6 [1] => Array ( [0] => Array ( [optionID] => 16 [isCorrect] => 0 ) [1] => Array ( [optionID] => 14 [isCorrect]...

Java ArrayIndexOutOfBoundsException When Trying to Test

java,tostring,shuffle
I seem to be getting an error with my deck of cards project. I'm trying to print out a shuffled deck of cards and I've had help already, but this error is now stopping me from progressing Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 51 at Pack.<init>(Pack.java:14) at PackTester.main(PackTester.java:14) Java Result: 1...

Random shuffling of elements in an array between 2 indexes VB.NET

vb.net,for-loop,random,arraylist,shuffle
I'm trying to shuffle elements between a certain number of indexes. Dim rng As New Random() For placeHolder As Integer = min To max Step -1 Dim swapIndex As Integer = rng.Next(min, max) Dim temp As Object = myList(placeHolder) myList(placeHolder) = myList(swapIndex) myList(swapIndex) = temp Next Where 'min' is the...

Spark Cassandra Connector keyBy and shuffling

cassandra,apache-spark,grouping,shuffle,connector
I am trying to optimize my spark job by avoiding shuffling as much as possible. I am using cassandraTable to create the RDD. The column family's column names are dynamic, thus it is defined as follows: CREATE TABLE "Profile" ( key text, column1 text, value blob, PRIMARY KEY (key, column1)...