[Question]
  [
## Intro
The Tetris Guidelines specify what RNG is needed for the piece selection to be called a Tetris game, called the Random Generator.
Yes, that's the actual name (["Random Generator"](https://tetris.wiki/Random_Generator)).
In essence, it acts like a bag without replacement: You can draw pieces out of the bag, but you cannot draw the same piece from the bag until the bag is refilled.
Write a full program, function, or data structure that simulates such a bag without replacement.
## Specification
Your program/function/data structure must be able to do the following:
* Represent a bag containing 7 distinct integers.
* Draw 1 piece from the bag, removing it from the pool of possible pieces. Output the drawn piece.
* Each piece drawn is picked uniformly and randomly from the pool of existing pieces.
* When the bag is empty, refill the bag.
## Other Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so lowest byte count wins!
* [Standard loopholes are forbidden.](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default)
* [You can use any reasonable I/O method.](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
### "Bonuses"
These bonuses aren't worth anything, but imaginary internet cookies if you are able to do them in your solution.
* Your bag can hold an arbitrary `n` distinct items.
* Your bag can hold any type of piece (a generic bag).
* Your bag can draw an arbitrary `n` number of pieces at once, refilling as needed.
  
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 5 bytes
Inspired by [Kevin Cruijssen's](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen) [05AB1E answer](https://codegolf.stackexchange.com/a/256676/96037)  
6 bytes without the bonus:
```
{7Þ℅⟑,
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJ7N8Oe4oSF4p+RLCIsIiIsIiJd)
**Explanation**
```
{7Þ℅⟑,
{         Loop forever
 7Þ℅      Random permutaton of range(7)
    ⟑,    Lazily evaluated lambda, print each item
```
Bonuses:
* 5 bytes for *Arbitrary n items*: [`{Þ℅⟑,`](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJ7w57ihIXin5EsIiwiIiwiNSJd). Implicitly takes an integer as the input.
* 5 bytes for *Generic bag*: [`{Þ℅⟑,`](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJ7w57ihIXin5EsIiwiIiwiW1wiY29va2llXCIsIFwiY29va2lcIiwgXCJjb2tpZVwiXSJd). Implicitly takes a list as the input. Same program as above :P
* 8 bytes for *Draw n items*: [`{7Þ℅?Ẏ⟑,`](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJ7N8Oe4oSFP+G6juKfkSwiLCIiLCI1Il0=). Slices the list until the input before applying it to the lambda.
[Answer]
# [R](https://www.r-project.org), ~~50~~ 40 bytes
*-10 bytes thanks to inspiration from Giuseppe*
```
{b=n=1;\()(b<<-c(b,sample(7)))[n<<-n+1]}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LY5BCsIwEEX3PcXgagZbsW5StD2FS3WRhlaLaVKSCSjiATyDm7oQvJK3sdKu_ufzePzny_UfxxW7xhfvwHWSffFWFqZIN3skLPM8UVjGXradrlAQ0c4Mm5mnh_vEP-rGeRbLwsuu01dM12IZ18EobqzBC016JIomMlKScaZOlToDnySD1BqOzobOg61BgA8tsIVVBvivw5YuFoLWezOjSFm9Da3HVg7aC07OePg2Hur7MX8)
A reuseable function that on each call returns a single random nunber in the range `1..7`, sampled across calls using the 'tetris' distribution.  
This is how I interpret the intent of the challenge.
A 62-byte recursive variant of this satisfies all 3 bonuses ([try it here](https://ato.pxeger.com/run?1=ZY9NTgQhEIX3fQqCGyrSyZC4MOPgRRwXQINDbH4CdLRjPImbdmHilTyFV7Dano1xU1V5PL689_Zels_SbCu-yo-puf7669bJFy2jFDdHFngG71gAw5g-HHrDNK8q5NGyDAB3EbV4Ke45enqBZng9U76DFFfkgmRvHkkgqhFFmg-2y94aW6Vh1I0z5bRmP9iCh_ZlwGVUwzmkh_VOTzhPqVRLAWEqzqTN2ZJUSJyCtoUkRzZid66xZv4VoEMUo-ZkMcHgKz7qqfkU98dIodtqiN1uTVVlVTmPMxN7VLibolmd7Bn-UaFrSmP_v_9hq70s2_4B)):
```
f={b=n=1;\(m,p)if(m)c((b<<-c(b,sample(p)))[n<<-n+1],f(m-1,p))}
```
---
# [R](https://www.r-project.org), 24 bytes
```
repeat cat(sample(7),"")
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWO4pSC1ITSxSSE0s0ihNzC3JSNcw1dZSUNCHSUFUw1QA)
Alternative: a full program that outputs an infinite sequence of random permutations of `1..7`.  
This probably satisfies the letter of the challenge, and other answers have used this approach, although it does seem rather trivial.
[Answer]
# JavaScript (ES6), 50 bytes
A function that draws one piece at a time.
```
m=f=_=>m^(m|=1<<(i=Math.random()*7))?-~i:f(m%=127)
```
[Try it online!](https://tio.run/##DcVNDoIwEAbQPaf4NqQzEgi4aQKMnMAbGE0DVDG0NUDc@HP16tu8u3matV@mx5b7MIwxOrFykYM7k3tL1bY0ydFst2IxfgiOeKeZu/w71ZZcKtVec7RhoXnc4CEom38tdNkwXgnQB7@GeSzmcCVLjAyUZR4pNDoohRrq5BVzk3ziDw "JavaScript (Node.js) – Try It Online")
### Commented
```
m =               // m (aka "the bag") is a global bitmask holding
                  // drawn pieces, initialized to a zero'ish value
f = _ =>          // f is a recursive function ignoring its argument
m ^ (             // if m is modified when ...
  m |= 1 << (     //   ... the floor(i)-th bit of m is set
    i =           //   where i is uniformly chosen
    Math.random() //   in [0, 7[
    * 7           //
  )               //
) ?               // then:
  -~i             //   return floor(i + 1)
:                 // else:
  f(              //   try again
    m %= 127      //   and reset m to 0 if it's 127 (0b1111111),
  )               //   meaning that the bag is empty
```
[Answer]
# [Raku](https://raku.org/), 23 bytes
```
{grab $||=SetHash(^7):}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/Or0oMUlBpabGNji1xCOxOEMjzlzTqvZ/cWKlQpqGpkJFhYKRwX8A "Perl 6 – Try It Online")
Ungolfed:
```
{
  state $bag ||= SetHash(0..6);
  $bag.grab;
}
```
This is a function which, when called repeatedly, will return the integers 0-6 in a random order, then the same integers in a (likely) different random order, and so on, *ad infinitum*.
Raku has a built-in data type `SetHash` which stores a set of objects, and has a `grab` method that chooses one of them randomly, removes it from the set, and returns it. All that's left to do for this challenge is the refilling. A state variable (`$` in the golfed version, `$bag` in the ungolfed one) stores the `SetHash`, which is reset to a new object with full contents (using `||`) when the variable is undefined, as on the first call to the function, or has become empty, as after every seventh call.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
[7L.r)˜ć,
```
Uses a bag with integers `[1,2,3,4,5,6,7]`. Outputs the random piece indefinitely on separated newlines.
[Try it online.](https://tio.run/##yy9OTMpM/f8/2txHr0jz9Jwj7Tr//xsDAA)
1. (9 bytes) Replace `7` with `I` for the first bonus, where `n` is given as input-integer: [try it online](https://tio.run/##yy9OTMpM/f8/2tNHr0jz9Jwj7Tr//5sAAA).
2. (8 bytes) Replace `7L` with `I` for the second bonus, where the bag is given as input-list: [try it online](https://tio.run/##yy9OTMpM/f8/2lOvSPP0nCPtOkC2UlJOopKOrqGBgY6usZ6RgbFlLAA).
3. (11 bytes) Add `Iô` after `˜` for the third bonus, where `n` is given as input-integer and it'll output those `n` items as a list each iteration: [try it online](https://tio.run/##yy9OTMpM/f8/2txHr0jz9BzPw1uOtOv8/28MAA). Will use a combination of the existing list and a new shuffled list if the bag doesn't hold enough items anymore (e.g. let's say \$n=3\$ and the first two iterations where `[4,2,5]` and `[1,7,3]`, then the third iteration will be `[6,a,b]`, where the `6` is from the existing bag, and `a,b` are two random integers from a new bag).
**Explanation:**
```
[          # Loop indefinitely:
 7L        #  Push a list in the range [1,7]
   .r      #  Randomly shuffle it
     )     #  Wrap the entire stack into a list
      ˜    #  Flatten it to a single list
       ć   #  Extract head; pop and push remainder-list and first item separately
        ,  #  Pop and output this first item
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 62 bytes
```
f=_=>x.match(i=Math.random()*7|0)?f(x=x[6]?'':x):(x+=i,i);x=''
```
[Try it online!](https://tio.run/##BcFRDoIwDADQfy@y1unClwZm5QSewBjTDCYzQM1YTD@8@3zvzV/eQk6fclxlGGuN9KSruoVLmCDRjcvkMq@DLID786/BPoKS3k@P3phOsQO1lA4JvZIx1e@iZGBqPF/a1lvLGGTdZB7dLC@IgFj/ "JavaScript (Node.js) – Try It Online")
I hope I understood question correctly
[Answer]
# Excel (ms365), 121 bytes
[![enter image description here](https://i.stack.imgur.com/traKF.png)](https://i.stack.imgur.com/traKF.png)
Formula in `A1`:
```
=LET(p,7,n,8,DROP(TAKE(REDUCE(0,SEQUENCE(ROUNDUP(n/p,0)),LAMBDA(a,b,VSTACK(a,SORTBY(SEQUENCE(p),RANDARRAY(p))))),n+1),1))
```
Idea here is that:
* 'p' - Represents the amount of distinct items in our bag;
* 'n' - Represents the amount of tokens we take out of the bag at once (with refilling it offcourse). You may change this to any reasonable integer;
* 'SEQUENCE(p)' - Represents our array. In this specific case we create an array of integers, but `SORTBY()` can take any array of any type. This however will start changing byte-count!
Below another sample where 'n' == 14 and another one where 'n' == 14 and 'p' == 3:
[![enter image description here](https://i.stack.imgur.com/58TrL.png)](https://i.stack.imgur.com/58TrL.png)[![enter image description here](https://i.stack.imgur.com/8ESCf.png)](https://i.stack.imgur.com/8ESCf.png)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage), ~~6~~ 5 bytes
```
ẊÐḶFY
```
Implements the first bonus
Runs until a pattern is repeated
-1 byte thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan)!
How?
```
ẊÐḶFY  : Main Link, One arg(Number of pieces)
Ẋ      : Shuffle; return a random permutation
 ÐḶ    : Loop; Repeat until the results are no longer unique
   F   : Flatten list
    Y  : Join z, separating by linefeeds
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fqse7uo6POHhjm1ukUuKk5KLocJLo5XMlWKhHAA)
[Answer]
# [Factor](https://factorcode.org/), ~~63~~ 62 bytes
```
[ 0 get [ 7 iota 7 sample >vector dup 0 set ] when-empty pop ]
```
[Try it online!](https://tio.run/##tU@7CsJAEOz9iiH9iZ2gYCs2NmIVUmwuqwbv5d0lIYjfHlfzBRZOMw@GWfZCOvs4nU@H434D7W3dOpIkoWf95cSPjp3mBEeWU6CPjOQab3Hn6NggRM55DLF1Ga3HdiqxwpUzSqwlyCSUyAbD2M2zaLognSSdCsONnWIb8ojgA6rpuYCghCZjsET1d9tEuVsopRwPqOkqqsD8z497L2jD1PP0Bg "Factor – Try It Online")
A quotation (anonymous function) that takes no arguments and outputs one piece each time it is called. You can look in the bag in between function calls with `0 get`.
[Answer]
# [Go](https://go.dev), 182 bytes
```
import(."math/rand";."golang.org/x/exp/slices")
func f()func()int{b:=[]int{}
return func()int{n:=Intn(7)
for;Contains(b,n);n=Intn(7){}
b=append(b,n)
if len(b)>6{b=[]int{}}
return n}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ZY8xasMwFIZ3n0IIAjKJ7XZpGrvq0qlboWMIRbZlRdh-ErICCcYn6RIKvUKhR-kdeohKdtwORcOT9PR_-t7rm1DnT82KmgmOWiYhkK1Wxsa4ai1-P9gquv36mO5IjFtm94lhUOIsxkI1DESsjEiOCT_qpGtkwTscBtUBClSR0FcSSrB9ntLtzm-GwHB7MID-epDSR7BA1i6oTPagwDqRjuQrCDOYey6ZU6Y1h3LsBLJCDQeSh_c3fT7Tf_EwDBf779HGz0ZC1AeCA0qptwuk5W3nDy2rOWmZ3jrGjsFpFEEypdeZvNtsMrlcuqTzdGGXezLuXQNErtDk8bJSdUpH3BZ2map7zUAW5Fn7lxXBixKxxnBWnpBDcMMsL5EEZPeyQzkT2JPCIZgRFDxWLtaUXvXzdziKInyxpv-VB7-mmc_nqf4A)
A generator function that returns a function.
When the returned function is called, it returns an int in the range `[0,7)`.
### "Bonuses"
#### Arbitrary `n` distinct items, 204 bytes
```
import(."math/rand";."golang.org/x/exp/slices")
func f(I[]int)func()int{b,l:=[]int{},len(I)
return func()int{e:=I[Intn(l)]
for;Contains(b,e);e=I[Intn(l)]{}
b=append(b,e)
if len(b)>=l{b=[]int{}}
return e}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ZZBNSsQwFMdxaU4RAgMJ03Z0xoXTGjeuuhNcDoOk07QT2r6WNAMzlJ7EzSB4CO_gBfQ0Jq1FwWSRvK_f-7_38prX5_dG7AqRS1wJBUhVTa1NQLLKkLeDyfzbz4_RRwNSCbNfaAEpiQKS16WAPKh1vjgu5LFZtKXayZYwlB1ghzMab7YKDHMWZfbXJV4Z8sHZ9V4pgcYMaWkOGvBvkgx5vInBAC3ZFmW1jh5qMFZaSxNPskj-CXc9SrhoGgnpEEQqw46bsHtedsnUq5-6yL4fZ_q6uBxEupEpwx2KJ2HX3nLprVYr78aeHuUScMjdMBZuZNU6qxKFpJVoNrZgK-DEnEysQn4dqbv1OlLzuUVCyG01ZehR27wSqPIwDBKfvboI-YDbwDaqi64RoHb0qXGZGSWzFItSS5GesEVILYxMsQJs9qrFiciJI7EeTQgODqtm4045v-qmnsT3ffIjnf_T3SN7x42cz-P7DQ)
Generator function now takes a list of elements to choose from.
#### Arbitrary `n` items + generic (`comparable`), 208 bytes
```
import(."math/rand";."golang.org/x/exp/slices")
func f[T comparable](I[]T)func()T{b,l:=[]T{},len(I)
return func()T{e:=I[Intn(l)]
for;Contains(b,e);e=I[Intn(l)]{}
b=append(b,e)
if len(b)>=l{b=[]T{}}
return e}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ZZDBatwwEIbpVYc-gxAEJOLdbbI5JHbVS0--Fbq3xZSxLTti5ZGQtZBg_CS9LIU-RN-i1_ZpKtldKFQ6COYfvvlGX7_19vLDQXOCXtEBNBI9OOvDlnVDYN_Pods8_vq51viWDRCedx6wZcWW9dYA9lvr-93LTr243Wh0o0YmSHfGhnbHA23s4MBDbVTFy2N1ECnh4jDVmcllLExzZhTyUhCvwtkjvTaoXJbHEgNyIyrSWV98tBii4MjrTIlC_RNPM6klOKewXUKiO5qotfggzVSvc-brBDXP616_37xdRNPaXNCJlElJY5jusvv7bL_fZw_xzKRXSHMZF4pZlVx1UMOYSgOcFB_ALQngq0imVOfyrtDvn54KfXsbuZjLiOCCfPKxzyDXGcXF8ktmT7lccEesCnuaHKBu-GeXOjvObloKxitoX2lEKA9BtVQjDc96pDX0LJHETK4IiQmrb9ZPlfLddJ3JNpsN-6su__OeSbzrt1wu6_sH)
Works for any `comparable` type (bool, int, float, string, pointer, channel, struct of comparables, array of comparables, typeset of comparable).
#### Arbitrary `n` items + generic (`comparable`) + `k` items at a time, 288 bytes
```
import(."math/rand";."golang.org/x/exp/slices")
func f[T comparable](I[]T)(func()T,func(int)[]T){b,l:=[]T{},len(I)
A:=func()T{e:=I[Intn(l)]
for;Contains(b,e);e=I[Intn(l)]{}
b=append(b,e)
if len(b)>=l{b=[]T{}}
return e}
return A,func(n int)(N[]T){for i:=0;i<n;i++{N=append(N,A())};return}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ZZFNitwwEIXJVqcQhgGJUf94OoFgR4FmVt40gfSuMUG2ZY9ou2xkNcwgdJJsmkAOkavkNJHsdphhvJGoV3r1vfLPX01__TOI8iwaiTuhAKlu6LVZR3Vnot8XU68-__2A5yJZR50wTxstoIrSddT0rYBm3etm87yRz8NmbFUpx4ii-gIlrk9HXPbdILQoWpmT7JQfKQkSoUc2nQoMDVVbsDbh_mYdayWQjKJ9wm-tViY8O2VggLQ0R3Wv08cejIcdScEkTeUr2TpUcDEMEqpJRKrGwbGgX3lri3mGQ1qaiwYs_9_2MxDggEQOE5SfhFXCt6n6Aqm6v7eHxfnA9oRSl86PnVsW9TgFD3skFFuUhUze0Mbs4YHtdjv20X8ONRJYIw1OuF-S1_MQWBnZjaHUibMknRgmRcALRTeQ2IN82gYS7w0J9zaEom_a97VAFMMwxf3B-nPCJ7sT5Gl_toMAVZLvQ-isSXRXYdFqKaoX7C2kFkZWPjc2T2rEhWii4EQdWiw4BFt1N_8Zzrd2mRmtVqvohs7fcTvkXqPH8YI-BnZD4u1b-pH6B7ddXq_z-Q8)
A function that returns 2 functions. The first function takes 1 item, the second function takes `k` items.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), (4) 5 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
7ẊṄ€ß
```
A full program that prints forever.
**[Try it online!](https://tio.run/##y0rNyan8///hrq6HO1seNa05PP/////mAA "Jelly – Try It Online")**
\$4\$ bytes - `ẊṄ€ß` - taking either an arbitrary alphabet size [TIO](https://tio.run/##y0rNyan8///hrq6HO1seNa05PP////@GRgA "Jelly – Try It Online") or an arbitrary alphabet (as a list) [TIO](https://tio.run/##y0rNyan8///hrq6HO1seNa05PP/////R6smJJeo6Cuop@ekgKiMxt7gktQjETMsszgDRufmlxakgRlFiUlImWHF6PlBTLAA "Jelly – Try It Online").
### How?
```
7ẊṄ€ß - Main Link: no arguments
7     - seven
 Ẋ    - (implicit range [1..7]) shuffle
   €  - for each:
  Ṅ   -   print with trailing newline
    ß - call this link again with the same arity
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 11 bytes
```
{l|:SHaPOl}
```
This is a function that takes as an argument a list of possible piece values (implementing the first two bonuses) and returns a single piece each time it is called.
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwU0dlZLUkqLM3My8_GIFK4VodU8FdX8F9RAFdS8FdR8F9WAF9ahYLpW81IoSBaulpSVpuharq3NqrII9EgP8c2ohIvt8FDIUqrkUAhQ0ICqRDNXkgipasABCAwA)
### Explanation
We store the current state of the bag in the global variable `l`. Initially, `l` is `[]`.
```
{l|:SHaPOl}
{         }  Define a function:
 l|:          If l is empty, set it to
    SHa       the function argument, randomly shuffled
       POl    Pop the first element from l and return it
```
[Answer]
# PHP, 79 bytes
```
$y=function()use(&$a){$a=$a!=[]?$a:range(0,6);shuffle($a);echo array_pop($a);};
```
[Try it online!](https://tio.run/##HY1BCsIwEEWvMsIgE@qiKwWnoQcRkaEkRpBkSBuwlJ49hq7@4/Hga9Bah1GDAq7WlzgtnxTJlNnRGcVsKBblZB/PEeWeJb4d9Zer4TkU77@OWsNuCgkkZ1lfmvRQO1efMhD@wELP0HaA2wFdZ2Brb2QY9voH "PHP – Try It Online")
### Commented
```
$y = function() use (&$a) {   // anonymous function with use clause by-reference
    $a = $a != []             // equal comparison, if $a is neither null nor empty array
        ? $a                  // then use $a        
        : range(0,6);         // else create range array
    shuffle($a);              // shuffle array        
    echo array_pop($a);       // splice off and return last element of $a
};
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~11~~ 8 bytes
```
LhP*SH,a
```
Implements the first bonus
-3 bytes thanks to [DLosc](https://codegolf.stackexchange.com/users/16766/dlosc)!
How?
```
LhP*SH,a  : One arg(Number of items)
       a  : First arg
L         : Loop x times;
 h        : Literal for 100
      ,   : Range zero to a
    SH    : Shuffle: random permutation of iterable
   *      : Map
  P       : Print
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJMaFAqU0gsYSIsIiIsIiIsIjciXQ==)
[Answer]
# [Zsh](https://www.zsh.org/), 35 bytes
```
exec<<(while shuf -i1-7)
f()read -e
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhY3lVMrUpNtbDTKMzJzUhWKM0rTFHQzDXXNNbnSNDSLUhNTFHRTIUp3F6UWpCaWKJgoaEBZ5gpp1gqpyRn5mhAVMEMB)
Uniquely for zsh, this is a function `f`, not a full program.
If you want to cheat and output infinitely, you only need the `while shuf -i1-7`.
Setup:
* `while shuf -i1-7`: repeatedly output the shuffled range 1 to 7
* `<()`: create a pipe from the output of that loop
* `exec<`: move that pipe to standard input
`f`:
* `read`: read one word from standard input
* `-e`: and print it
[Answer]
# [Python 3](https://docs.python.org/3/), 59 bytes
-6 bytes thanks to @att
```
from random import*
while[*map(print,sample(range(7),7))]:1
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P60oP1ehKDEvBUhl5hbkF5VocZVnZOakRmvlJhZoFBRl5pXoFCfmFuSkagCVpadqmGvqmGtqxloZ/v8PAA "Python 3 – Try It Online")
Infinitely prints integers.
I dont know if this is valid: (54 bytes)  
Prints all 7 integers of permutation in one line before a newline.
```
from random import*
while 1:print(*sample(range(7),7))
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P60oP1ehKDEvBUhl5hbkF5VocZVnZOakKhhaFRRl5pVoaBUn5hbkpGoAFaWnaphr6phrav7/DwA "Python 3 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 149 bytes
```
import System.IO.Unsafe
import System.Random
import Data.List
d(o,[])=d([],o)
d(o,p)=(\n->(n:o,p\\[n]))$(p!!)$unsafePerformIO$randomRIO(0,length p-1)
```
[Try it online!](https://tio.run/##VY69CsIwFEb3PkULGRJog4IgCnVyKQgVxantcCG3Ntj8kFwHnz5qwcHxnOF83wTxgfOckjbeBcqvr0hoZNPKm40wYvbvL2CVMz95BAJ50pEyxV3ZDaJWvBtKJxb2oua9rQ7c7j/Q950dhGDcF4VgzyV@xjC6YJqWhaV7aVq@Kme0d5pyX61FMqBt7YO2xAgemG92zIDnE4KSYyTBNGEAwlyxz/Rayu3w/ZHe "Haskell – Try It Online")
[Answer]
# Clojure, 56 bytes
```
(run! #(run! println %)(repeatedly #(shuffle(range 7))))
```
Creates an infinite list containing random permutations of 0 to 6 and prints each number.
[Try it online!](https://tio.run/##S87JzyotSv3/X6OoNE9RQRlCFRRl5pXk5CmoamoUpRakJpakpuRUKhgDpYszStPSclI1ihLz0lMVzDWB4P9/AA "Clojure – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 7 bytes
```
7>ℕ≜₁|↰
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/39zuUcvUR51zHjU11jxq2/D///8oAA "Brachylog – Try It Online")
This is a predicates that unifies its output with a random integer between 0 and 6, exhausting each possibility before beginning a new cycle.
[Try generating 14 random unifications here!](https://tio.run/##SypKTM6ozMlPN/r/qG3Do6bGh9sWHNr5qHHLf3O7Ry1TH3XOAYrVAKX@//8fBQA)
You can change `7` to any other number to get bigger bags.
### Explanation
```
7>ℕ        Take an unknown integer between 0 and 6
    ≜₁     Assign a value to it, with a random choice
      |    Else
       ↰   Recursive call
```
Since our variable is constrained in `[0..6]`, `≜₁` will randomly unify it with one of those 7 values, leaving a choice point for each one. Brachylog will try each choice point when asked (e.g. with `ᶠ - findall`, failure loops, or by pressing `;` in Prolog’s REPL), so each integer value. `|` creates another choice point that will get called only once all the choice points created by `≜₁` are exhausted.
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 11 \log\_{256}(96) \approx \$ 9.05 bytes
```
[7R7zPZw{ZK
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuharo82DzKsCosqro7whIlAJmAIA)
Port of [mathcat's Vyxal answer](https://codegolf.stackexchange.com/a/256680/114446).
#### Explanation
```
[7R7zPZw{ZK
[            # Forever:
         ZK  #   Print
        {    #   Each element of
      Zw     #   A random element of
   7zP       #   The permutations
 7R          #   Of range(7)
```
#### Bonuses
* Arbitrary `n` items: \$ 13 \log\_{256}(96) \approx \$ 10.70 bytes, [`[z0Rz0zPZw{ZK`](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhZro6sMgqoMqgKiyqujvCFiUKkFC00hDAA)
* Generic bag: \$ 12 \log\_{256}(96) \approx \$ 9.88 bytes, [`[z0DLzPZw{ZK`](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhZroqsMXHyqAqLKq6O8IUJQmQV7otUTk5LVdRTUU1LTQFR6RiaIysrOUY-FqAEA)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 60 bytes
```
b;f(i,j){b-127||(b=0);for(;b&1<<(i=rand()%7););b|=1<<i;j=i;}
```
[Try it online!](https://tio.run/##VY9Bj4IwEIXv/RUTNphpRCPGhMShe9/EePPmhVLQIVoM1L0Ivx1bPDmnyTfzXt4rV5eynCZNNXLSyJdepdtsGFCrjaS67ZD0Is1zZNUV1qCMM0mS9KA8ZGoU0zj9sC1vT1NB3jvD7fr6K77QjXVggq2De8EW/1s2El4CICAm4bd@9nd8r/B4OhyknGlIwGpDwMtlnu7oowJ4dF5ZY/Tnqq5w3FqI11uzh9icbZQAJ1BjsAi/7KvFmfKF4PF0PUbqM9F8H8U4vQE "C (gcc) – Try It Online")
## Explanation
```
b; // Bag: initialized with nothing selected
f(i,j){
  b-127||(b=0); // Reset bag when all 7 pieces selected
  for(;b&1<<(i=rand()%7);); // Find a random unselected piece
  b|=1<<i; // Mark it as selected
  j=i; // Return the piece
}
```
]