Haskell, (削除) 94 (削除ここまで) 81(削除) 81 (削除ここまで) 78 bytes
import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else;last$((i+)<$>f n):[return i|i<n]
Quite similar to @dfeuer's, but using do notation.
Saved 13 bytes by removing whitespace, thanks to @dfeuer.
Haskell, (削除) 94 (削除ここまで) 81 bytes
import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else(i+)<$>f n
Quite similar to @dfeuer's, but using do notation.
Saved 13 bytes by removing whitespace, thanks to @dfeuer.
Haskell, (削除) 94 (削除ここまで) (削除) 81 (削除ここまで) 78 bytes
import System.Random
f n=do i<-randomRIO(1,n);last$((i+)<$>f n):[return i|i<n]
Quite similar to @dfeuer's, but using do notation.
HaskellHaskell, 94(削除) 94 (削除ここまで) 81 bytes
import System.Random
f n=do
i<-randomRIO(1,n)
if i<n
then return i
else (i+)<$>f n
import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else(i+)<$>f n
Quite similar to @dfeur's@dfeuer's, but using do notation.
Saved 13 bytes by removing whitespace, thanks to @dfeuer.
Haskell, 94 bytes
import System.Random
f n=do
i<-randomRIO(1,n)
if i<n
then return i
else (i+)<$>f n
Quite similar to @dfeur's, but using do notation.
Haskell, (削除) 94 (削除ここまで) 81 bytes
import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else(i+)<$>f n
Quite similar to @dfeuer's, but using do notation.
Saved 13 bytes by removing whitespace, thanks to @dfeuer.
Haskell, 94 bytes
import System.Random
f n=do
i<-randomRIO(1,n)
if i<n
then return i
else (i+)<$>f n
Quite similar to @dfeur's, but using dodo notation.
Haskell, 94 bytes
import System.Random
f n=do
i<-randomRIO(1,n)
if i<n
then return i
else (i+)<$>f n
Quite similar to @dfeur's, but using do notation.
Haskell, 94 bytes
import System.Random
f n=do
i<-randomRIO(1,n)
if i<n
then return i
else (i+)<$>f n
Quite similar to @dfeur's, but using do notation.