## What does this semantic specification do about shuffling a single card of a Deck?

I have 2 constructor functions and 2 additional function:

declare: d,d' = deck; c, c' = card

Constructor 1)

CreateDeck();

Constructor 2)

addCard(d,c); 

addCardRandomly(d', c');

CardsInTheDeck(d');  (it returns "CardsInTheDeck(d)+1" when called with addCard(d,c) constructor obviously) 

now, what happens when the function addCardRandomly(d',c') is called with the addCard(d,c) constructor? This is the semantic specification given by the book:

if    random(CardsInTheDeck(d') = CardsInTheDeck(d')+1): then  addCard(d',c');  else addCard(addCardRandomly(d, c'), c); 

What I think it does is: Given that a deck of card can be treated as a queue, we can take the card c that our constructor has to insert inside the deck and: if the random gives back the first position of the queue then simply put the card on that position;

else swap that card with the card we just randomized and insert the cards over the card in that position once at time over the card we randomized itself. Eg:

Cards are 1 2 3 4 5 6 7 8

We have to insert 9

if random = 5

it becomes 1 2 3 4 9 5 6 7 8

(case where random = 9 omitted because trivial)

Is it correct? What makes this recursive specification so complex? How can i visualize and understand this kind of ideas generally? How can I explain this concept once the final solution is met? This looks so complex to me. Thanks!

## Is there a PCI Requirement for shuffling digits while accepting PIN?

The following image shows a PIN entry device which shuffles the digits.

I’ve seen this question, but it doesn’t cover why companies are still doing this.

I looked at the POS PIN Entry Device and the Software-based PIN Entry on COTSSecurityRequirements requirements and neither of them seems to have anything about shuffling the digits.

Is there a requirement or specification that I’m missing?

## Arrayformula stops working after shuffling rows

I have a pretty extensive sheet where in many columns I use arrayformula to automatically fill data in from various other spreadsheets. The problem I have is when I need to rearrange rows then what is in that row output from arrayformula stays there as plain text after moving and that prevents the arrayformula from working because it cannot overwrite data in those cells that now contain text.

Is there a workaround? I don’t want to constantly need to delete the cells manually many times a day.

## A shuffling problem from number theory?

Fix integers $$n>0$$ and $$t>0$$.

Is it true that for every pair of integer vectors $$(a_1,\dots,a_n)\in\mathbb Z^n$$ $$(b_1,\dots,b_n)\in\mathbb Z^n$$ with $$0 and $$0 at every $$i,j\in\{1,\dots,n\}$$ there are primes $$p_{1,1},\dots,p_{1,r},p_{2,1},\dots,p_{2,r}<2^{poly(t\log n)}$$ with $$r\asymp poly(t\log n)$$ and integers $$\ell_1,\ell_2\asymp poly(t\log n)$$ and integers $$0\leq e_{jk},m_{jk} at every $$j\in\{1,2\}$$ and $$k\in\{1,\dots,r\}$$ with $$2^{\ell_1} a_j' holding true ($$i_j$$ indicates each $$j$$ gets a separate $$i_j$$ with $$b’_{i_j}$$ between scaled $$a_j$$ and $$a_{j+1}$$) at every $$j\in\{1,\dots,n\}$$ where $$j\rightarrow i_j$$ is a one to one map and $$b_j’$$ and $$a_j’$$ are derived as follows:

$$a_j’=f_{11}(f_{12}(\dots f_{1r}(a_j)))$$ $$b_j’=f_{21}(f_{22}(\dots f_{2r}(b_j)))$$

where $$f_{jk}(x)\equiv x^{e_{jk}}\bmod p_{jk}$$ holds (remainder in $$(0,p_{jk})$$)?

## A shuffling problem from number theory?

Fix integers $$n>0$$ and $$t>0$$.

Is it true that for every pair of integer vectors $$(a_1,\dots,a_n)\in\mathbb Z^n$$ with $$0 and $$(b_1,\dots,b_n)\in\mathbb Z^n$$ with $$0 at every $$i,j\in\{1,\dots,n\}$$ there is a prime $$p<2^{poly(nt)}$$, $$\ell\asymp poly(nt)$$, integer $$0 and a permutation $$\sigma$$ such that $$2^\ell a_j holds at every $$i_j,j\in\{1,\dots,n\}$$ where $$b_i’\equiv mb_i\bmod p$$ (remainder in $$(0,p)$$)?

## Are there any blockchain’s that has a built in tumbler or coin shuffling technology built into their code?

I know dash has some kind of mixing technology in their blockchain using their master nodes, but are there any other blockchains that has a built in coinjoin or coin shuffling technology built into their code? I know Monero uses ring signatures, but I’m more interested in just coinjoin or coin shuffling technology that is in blockchains. I know it might not be 100% private.

## Efficiently shuffling items in $N$ buckets using $O(N)$ space

I’ve run into a challenging algorithm puzzle while trying to generate a large amount of test data. The problem is as follows:

• We have $$N$$ buckets, $$B_1$$ through $$B_N$$. Each bucket $$B_i$$ maps to a unique item $$a_i$$ and a count $$k_i$$. Altogether, the collection holds $$T=\sum_1^N{k_i}$$ items. This is a more compact representation of a vector of $$T$$ items where each $$a_i$$ is repeated $$k_i$$ times.

• We want to output a shuffled list of the $$T$$ items, all permutations equally probable, using only $$O(N)$$ space and minimal time complexity. (Assume a perfect RNG.)

• $$N$$ is fairly large and $$T$$ is much larger; 5,000 and 5,000,000 in the problem that led me to this investigation.

Now clearly the time complexity is at least $$O(T)$$ since we have to output that many items. But how closely can we approach that lower bound? Some algorithms:

• Algorithm 1: Expand the buckets into a vector of $$T$$ items and use Fisher-Yates. This uses $$O(T)$$ time, but also $$O(T)$$ space, which we want to avoid.

• Algorithm 2: For each step, choose a random number $$R$$ from $$[0,T-1]$$. Traverse the buckets, subtracting $$k_i$$ from $$R$$ each time, until $$R<0$$; then output $$i$$ and decrement $$k_i$$ and $$T$$. This seems correct and does not use extra space. However, it takes $$O(NT)$$ time, which is quite slow when $$N$$ is large.

• Algorithm 3: Convert the vector of buckets into a balanced binary tree with buckets at the leaf nodes; the depth should be close to $$\log_2{N}$$. Each node stores the total count of all the buckets under it. To shuffle, choose a random number $$R$$ from $$[0,T-1]$$, then descend into the tree accordingly, decrementing each node count as we go; when descending to the right, reduce $$R$$ by the left count. When we reach a leaf node, output its value. It uses $$O(N)$$ space and $$O(T\log{N})$$ time.

• Algorithm 3a: Same as Algorithm 3, but with a Huffman tree; this should be faster if the $$k_i$$ values vary widely, since the most often visited nodes will be closer to the root. The performance is more difficult to assess, but looks like it would vary from $$O(T)$$ to $$O(T\log{N})$$ depending on the distribution of $$k_i$$.

Algorithm 3 is the best I’ve come up with. Here are some illustrations to clarify it:

Does anyone know of a more efficient algorithm? I tried searching with various terms but could not find any discussion of this particular task.