Skip to main content
1 of 7
ngm
  • 4.4k
  • 9
  • 29

R, 66 bytes

f=function(n,x=sample(seq(n)-1,1))"if"(x,{cat(x," ");f(x)},cat(0)) 

Try it online!

ngm
  • 4.4k
  • 9
  • 29