samedi 25 mars 2017

How to populate list in SML with random numbers

fun list(n) = 
let 
    val list = []
    val nextInt = Random.randRange (1,100)
    val r = Random.rand (1,1)
    val x1 = nextInt r
in 
if n = 0 then (return list)
else (
    list @ x1
    list(n-1));

 list(50);

I'm wanting to make a recursive function that will populate a list with a given amount of numbers. Those numbers should all be in a random range. However, I'm not very familiar with SMLNJ. I'm getting the error stdIn:15.1 Error: syntax error found at EOF So clearly I have a syntax error somewhere, but I don't see a syntax error (I'm sure its obvious to anyone with experience but to my new eyes I can't find it).




Aucun commentaire:

Enregistrer un commentaire