shuffle

Shuffle struct by Int

ぐ巨炮叔叔 提交于 2019-12-11 16:59:03
问题 How I can shuffle my struct by variable priority and display in TableView? So now I have 20 documents in my struct, but later I will have 100+ documents in my struct. 5 or 7 or 10 documents will have priority from 10 to 1, other documents have priority 0. Me need display 5 or 7 or 10 documents on top position in tableView. Other documents which have priority 0 must be located after firsts 5 or 7 or 10 documents in random order. I. e. the firsts 5 or 7 or 10 documents should be placed

Is mask adaptive in __shfl_up_sync call?

萝らか妹 提交于 2019-12-11 16:55:53
问题 Basically, it is a materialized version of this post. Suppose a warp need to process 4 objects(say, pixels in image), each 8 lanes are grouped together to process one object: Now I need do internal shuffle operations during processing one object(i.e. among 8 lanes of this object), it worked for each object just setting mask as 0xff : uint32_t mask = 0xff; __shfl_up_sync(mask,val,1); However, to my understanding, set mask as 0xff will force the lane0:lane7 of object0(or object3? also stuck on

Shuffle a string input by user

那年仲夏 提交于 2019-12-11 15:35:37
问题 #include <stdio.h> #include <stdlib.h> #include <string.h> char rand(char x); int main() { char input[80] = {0}; char rando[80] = {0}; char choice = 0; char rando2[80] = {0}; if(strlen(input) >= 10 && strlen(input) <= 80); { printf("Please enter a string with 10-80 characters: "); scanf("%s", input); printf("Orginal string: %s\n", input); rando = my_rand(input); printf("New string: %s\n", rando); } else{ return 0; } printf("Would you like to shuffle this string again?(y or n): "); scanf("%c\n

Fischer Yates shuffle in coffee-script

*爱你&永不变心* 提交于 2019-12-11 12:58:19
问题 Assuming that Math.random() produces evenly distributed random numbers between 0 and 1, is this a correct implementation of the Fischer Yates shuffle? I am looking for a very random, even distribution, where the number of shuffled elements in an input array ( arr ) can be specified (as required ). shuffle = (arr, required)-> rnd = (int) -> r = Math.random() * int Math.round r len = arr.length-1 for i in [len..1] random = rnd(i) temp = arr[random] arr[random] = arr[i] arr[i] = temp break if i

Shuffle an array while making each index have the same probability to be in any index

走远了吗. 提交于 2019-12-11 07:56:38
问题 I want to shuffle an array, and that each index will have the same probability to be in any other index (excluding itself). I have this solution, only i find that always the last 2 indexes will always ne swapped with each other: void Shuffle(int arr[]. size_t n) { int newIndx = 0; int i = 0; for(; i > n - 2; ++i) { newIndx = rand() % (n - 1); if (newIndx >= i) { ++newIndx; } swap(i, newIndx, arr); } } but in the end it might be that some indexes will go back to their first place once again.

Trying to shuffle multiple arrays in javascript but in the same way? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-11 06:31:25
问题 This question already has answers here : Shuffling Multiple arrays Javascript [duplicate] (2 answers) Closed 2 years ago . I want to randomly shuffle these two arrays in the same function var array1 = [1,2,3,4,5]; var array2 = [6,7,8,9,10]; So that it returns each array randomly shuffled such as 4,2,3,5,1 7,9,6,8,10 Also on return I want a line break between the two, please help? 回答1: Added shuffle method to Array.prototype for easy access - returns a modified array keeping the original

What's the logic behind the SomeArray.sort ( function() { … } ) statement?

落爺英雄遲暮 提交于 2019-12-11 04:38:13
问题 var array = [3,9,23,76,1,54,21,12,0,9,2]; var shuffled = array.sort(function() {return 0.5 - Math.random()}); console.log(shuffled); I'm aware of the results, and also satified with them. The code above returns a shuffled order of the elements of my array. I'm puzzled by why it results in that output. What's the point of the function inside of the .sort and how does it contribute to the output? 回答1: The function actually takes two arguments, which are 2 items from the array. The purpose is to

How can I shuffle an array of filenames that have spaces in them?

痞子三分冷 提交于 2019-12-11 03:08:10
问题 I have an array of filenames that may contain spaces in them. I am using the shuf command but it uses the spaces in the filenames as a delimiter and breaks up the filenames when it shuffles. Is there a way around this or do I have to abandon the shuf command? Any suggestions? #!/bin/bash vids=() vids+=("file with spaces.txt") for arr in "${vids[@]}"; do echo -e "$arr\n" done vids=( $(shuf -e "${vids[@]}") ) #shuffle contents of array for arr in "${vids[@]}"; do echo -e "$arr\n" done exit 0

How do I shuffle a multidimensional list in Python

元气小坏坏 提交于 2019-12-11 02:28:22
问题 I know how to shuffle a simple List in Python by using the shuffle function from the random library shuffle(myList) But how do I shuffle a multidimensional list? myList[][] shuffle(myList) didn't work. 回答1: You have to shuffle the top level list, then you can map the shuffle function to the sub lists like this in Python 2 from random import shuffle foo = [] foo.append([1, 2, 3]) foo.append([4, 5, 6]) foo.append([7, 8, 9]) shuffle(foo) map(shuffle, foo) print foo See python 2 fiddle And like

Determine if a sequence is an interleaving of a repetition of two strings

隐身守侯 提交于 2019-12-10 22:48:00
问题 I have this task: Let x be a string over some finite and fixed alphabet (think English alphabet). Given an integer k we use x^k to denote the string obtained by concatenating k copies of x. If x is the string HELLO then x^3 is the string HELLOHELLOHELLO. A repetition of x is a prefix of x^k for some integer k. Thus HELL and HELLOHELL are both repetitions of HELLO. An interleaving of two strings x and y is any string that is obtained by shuffling a repetition of x with a repetition of y. For