g | x | w | all
Bytes Lang Time Link
014APLDyalog Unicode250509T181346ZMat_rdv
065TIBASIC TI83 Plus250424T162828Zmadeforl
140C# 10250423T131633Zjuanferr
032Zsh + GNU coreutils250427T172925Zcorvus_1
063Pharo250426T010154Zchunes
046Arturo250425T224146Zchunes
036R250425T060453Zpajonk
082Google Sheets250425T162935Zdoubleun
nanGoogle Sheets250422T205133Zz..
076CASIO BASIC CASIO fx9750GIII250424T153241Zmadeforl
099C gcc250424T220733ZAShelly
112Maple250424T171045Zdharr
090Julia250423T185859ZSort of
079JavaScript ES7250422T211837ZArnauld
051PowerShell250423T220301ZZaelin G
011Uiua 0.16.0dev.1250423T152416ZTbw
054Perl 5 MListUtil=min MListMoreUtils=samples ln250423T144418ZXcali
020APL+WIN250423T124913ZGraham
00805AB1E250423T095710ZKevin Cr
027Charcoal250423T092650ZNeil
077Python 3250422T152742ZJitse
043Wolfram Language Mathematica250423T040418Zatt
007Vyxal250423T013222Zlyxal
042Ruby250423T004234ZValue In
005Jelly250422T193822ZJonathan

APL(Dyalog Unicode), 14 bytes SBCS

∊⊢?⍨¨|⍨,⍨⌊⍤÷⍴⊢

X is the left argument, Y is the right.

Try it on APLgolf!

Explanation

             ⊢   right argument, Y
            ⍴    reshape
           ÷     divide
          ⍤      postprocess
         ⌊       floor
         ⌊⍤÷     floor division; X//Y
         ⌊⍤÷⍴⊢   repeat Y (X//Y) times
        ⍨        swap left and right arguments
       ,         concatenate
       ,⍨        append left argument to the end 
      ⍨       
     |           modulo
     |⍨          Y%X (arguments are swapped)
     |⍨,⍨⌊⍤÷⍴⊢  repeat Y while the sum is less than X, append the remainder
    ¨            each
   ⍨          
  ?              deal: A?B returns A different numbers in range 1..B
 ⊢            
 ⊢?⍨¨           for each number N on the right: deal N times in range Y
 ⊢?⍨¨|⍨,⍨⌊⍤÷⍴⊢ solution but as vector of vectors: new subvector starts after exhausting all values in 1..Y
∊                enlist: make one vector from all values in order
∊⊢?⍨¨|⍨,⍨⌊⍤÷⍴⊢ solution

TI-BASIC (TI-83 Plus), 72 67 65 bytes

-5 bytes thanks to MarcMush

Input A
Input B
B→dim(L₁
For(N,1,A
If not(max(L₁
cumSum(1 or L₁→L₁
Repeat L₁(E
randInt(1,B→E
End
Disp L₁(E
0→L₁(E
End

TI calculators with OS 2.53MP (and the TI-84+/SE) have a RandIntNoRep function that would make this a lot easier, but I don't have one of those anymore. gotta look into upgrading

C# 10, 202 154 140 bytes

f=(x,y)=>{Random r=new();List<int> a=new();for(int i=-1;i<x/y;i++)a.AddRange(Enumerable.Range(1,y).OrderBy(x=>r.Next(y)));return a.Take(x);}

Accepts 2 ints and returns an IEnumerable<int>.

Try it on JDoodle.

Ungolfed:

Random r = new();
List<int> a = new();
for (int i = -1; i < x / y; i++)                                // Repeat 1 + x/y times:
    a.AddRange(Enumerable.Range(1, y).OrderBy(x => r.Next(y))); // Get the range 1-y, sort it randomly and append to list
Console.WriteLine(string.Join(',', a.Take(x)));                 // Take the first x numbers from list and print them

C# 12, 198 150 138 bytes

Shorter empty list initialiser ([] vs new()).

f=(x,y)=>{Random r=new();List<int> a=[];for(int i=-1;i<x/y;i++)a.AddRange(Enumerable.Range(1,y).OrderBy(x=>r.Next(y)));return a.Take(x);}

Edit: Turned it into a function thanks to Themoonisacheese's comment.

Zsh + GNU coreutils, 32 bytes

(repeat $1 shuf -i1-$2)|head -$1

Expects x, y as arguments.

Attempt This Online!

Pharo, 63 bytes

[:x :y|((1to:x)flatCollect:[:x|(1to:y)asArray shuffle])first:x]

Arturo, 46 bytes

$[x y]->take flatten map@.of:x@1..y=>shuffle x

Try it!

R, 44 36 bytes

\(x,y)sapply(1:x,\(i)sample(y))[1:x]

Attempt This Online!

Google Sheets, 82 bytes

=query(tocol(map(1:1,lambda(_,sort(sequence(A3),randarray(A3),))),,1),"limit "&A2)

Put \$X\$ in cell A2, \$Y\$ in cell A3 and the formula in cell B2.

screenshot

(cheats a bit)

Google Sheets, 103 91 bytes

-12 bytes thanks to Jonathan Allan

Expects \$X\$ in A1 and \$Y\$ in A2.

=QUERY(REDUCE(,SEQUENCE(A1),LAMBDA(a,_,{a;SORT(SEQUENCE(A2),RANDARRAY(A2),)})),"limit "&A1)

Stacks on top of each other \$X\$ randomized sequences of numbers from \$1..Y\$ and constrains the result to the first \$X\$ values.

CASIO BASIC (CASIO fx-9750GIII), 92 76 bytes

?→A
?→B
{0→List1
For 1→N To A
Not Max(List1⟹Seq(K,K,1,B,1→List1
Do
RanInt#(1,B
LpWhile Not List1[Ans
List1[Ans◢
0→List1[Ans
Next

I think this is right

input x first, then y

try a longer version online at basic.crevola.org

C (gcc), 99 bytes

f(x,y){int i,a[y],n=0;for(;x--;a[i]=a[--n]){
if(!n)for(;n<y;a[n++]=n);printf("%d ",a[i=rand()%n]);}}

Try it online!

A simple algorithm that (re)generates the pool when empty, and swaps each picked value with the shrinking end.

Maple, 112 bytes

proc(x,y)L:=[$y];S:=();to x do r:=rand(1..nops(L))();S,=L[r];L:=subsop(r=(),L);if L=[] then L:=[$y] fi od;S end;
proc(x,y)
L:=[$y];  # initialize list to [1..y]
S:=();    # initialize output sequence to NULL
to x do
  r:=rand(1..nops(L))();  # find random index into current list
  S,=L[r];                # augment sequence with new value
  L:=subsop(r=(),L);      # remove value from list
  if L=[] then L:=[$y] fi # reset list if empty
od;
S;                        # return sequence
end;

I thought a recursive function would be shorter, but it wasn't

Julia, 90 bytes

+(X,Y)=begin Z=[];map(x->begin(Z==[])&&(Z=[1:Y...]);popat!(Z,rand(1:length(Z)))end,1:X)end

Attempt This Online!

Grateful that rand() is in Base.

ATO doesn't have StatsBase but the following is 85 bytes:

using StatsBase
+(x,y)=[sample([1:y...],min(x,y);replace=false);(x>y) ? (x-y+y) : []]

JavaScript (ES7), 79 bytes

Expects (y)(x).

y=>g=(x,n,i=Math.random()*y)=>x?n>>i&1?[-~i,...g(x-1,n^1<<i)]:g(x,n||2**y-1):[]

Try it online!

Commented

y =>                // outer function taking y
g = (               // inner recursive function taking:
  x,                //   x
  n,                //   n = bit-mask, initially undefined
  i = Math.random() //   i = random value in [0, y[
      * y           //   (implicitly floored in bitwise operations)
) =>                //
x ?                 // if x is not zero:
  n >> i & 1 ?      //   if the i-th bit of n is set:
    [               //     update the output array:
      -~i,          //       append floor(i) + 1
      ...g(         //       do a recursive call:
        x - 1,      //         decrement x
        n ^ 1 << i  //         clear the i-th bit of n
      )             //       end of recursive call
    ]               //     end of array update
  :                 //   else:
    g(              //     do a recursive call:
      x,            //       pass x unchanged
      n ||          //       pass either n unchanged,
      2 ** y - 1    //       or with y bits set if cleared
    )               //     end of recursive call
:                   // else:
  []                //   stop

PowerShell, 51 bytes

param($x,$y)for(;$x-gt0;$x-=$y){1..$y|random -c $x}

Try it online!

Uiua 0.16.0-dev.1, 11 bytes SBCS

˜↙♭≡°⍆+1↯⤙⇡

Try on Uiua Pad!

Takes Y X on stack.

Explanation

˜↙♭≡°⍆+1↯⤙⇡
      +1↯⤙⇡ # X copies of range 1...Y
    ≡°⍆     # randomize each (literally "un"-"sort")
˜↙♭         # flatten and take the first X

Perl 5 -MList::Util=min -MList::MoreUtils=samples -ln, 54 bytes

map{say}samples min($_,$t//=<>),1..$_;($t-=$_)>0&&redo

Try it online!

APL+WIN, 20 bytes.

Prompts for y followed by x.

x↑∊y?¨(⌈(x←⎕)÷y)⍴y←⎕

Try it online! Thanks to Dyalog Classic

05AB1E, 8 bytes

иL€.r˜¹£

Inputs in the order \$X,Y\$. Outputs as a list.

Try it online.

A program derived from my answer to the related challenge would be 1 byte longer:

FIL.r)˜ć,

Inputs in the order \$X,Y\$. Outputs each value on a separated newline.

Try it online.

Explanation:

и          # Repeat the second (implicit) input `Y` the first (implicit) input `X`
           # amount of times as list
 L         # Convert each inner `Y` to a list in the range [1,Y]
  €        # Map over each of those inner [1,Y]-lists
   .r      #  Randomly shuffle it
     ˜     # Flatten this list of lists
      ¹£   # Only keep the first input `Y` amount of leading values
           # (after which this list is output implicitly)

F          # Loop the first (implicit) input `X` amount of times:
 IL        #  Push a list in the range [1, second input Y]
   .r      #  Randomly shuffle it
     )     #  Wrap everything on the stack into a list
      ˜    #  Flatten it
       ć   #  Extract its head; push remainder-list and first item separately
        ,  #  Pop and print this first item with trailing newline

Charcoal, 27 bytes

NθFN«F∧¬υθ⊞υ⊕κ≔⟦‽υ⟧ι≔⁻υιυIι

Try it online! Link is to verbose version of code. Takes inputs in the order Y, X. Explanation:

Nθ

Input Y.

FN«

Repeat X times.

F∧¬υθ⊞υ⊕κ

If all of the values are exhausted, replace all the values 1..Y.

≔⟦‽υ⟧ι

Pick a random value and wrap it in a list.

≔⁻υιυ

Perform list subtraction to remove it from the values.

Iι

Output it. (As a list, this outputs each value on its own line.)

Python 3, 77 bytes

f=lambda x,y:x*[x]and sample(range(1,y+1),y)[:x]+f(x-y,y)
from random import*

Try it online!

-3 bytes thanks to Jonathan Allan

Wolfram Language (Mathematica), 43 bytes

Table[##&@@RandomSample@Range@#2,#]~Take~#&

Try it online!

Input [X, Y].

Vyxal, 7 bytes

ẋvÞ℅f⁰Ẏ

Try it Online!

Taking a L here because shuffle is two bytes and because input cycling works against me

Ruby, 42 bytes

Rather conveniently, calling sample with a number bigger than the length of the array shuffles it (as if you called it with the array length), saving bytes over having to get the minimum of x and y.

f=->x,y{x>0?[*1..y].sample(x)+f[x-y,y]:[]}

Try it online!

Jelly, 5 bytes

Ẋ{ⱮFḣ

A dyadic Link that accepts the range size, \$Y\$, on the left and the desired count, \$X\$, on the right and yields a list of the \$X\$ draws from \$[1,Y]\$.

Try it online!

How?

Shuffle each of \$X\$ copies of \$[1,Y]\$, flatten this list of lists, and then only keep the first \$X\$.

Ẋ{ⱮFḣ - Link: non-negative integer, Y; non-negative integer, X
  Ɱ   - map across {v in [1..X]} with - f(Y, v):
 {    -   using Y as the arguments - f(Y, Y):
Ẋ     -     shuffle {[1..Y]}
   F  - flatten
    ḣ - head to index {X}