JavaScript (ES6), 3838 37 bytes
-1 byte thanks to @Arnauld
f=n=>alert(f=n=>[n,...n)||n&&f?f(Math.random()*n|0):[]] // Alert is replaced with consolef=n=>[n,.log to avoid the popups alert=console.log f=n=>alert(.n)||n&&f?f(Math.random()*n|0):[]] <input type=number id=a><button onclick="fonclick="console.log(af(+a.value))">Test</button>