在 SML 中生成随机数 [英] Generating a random number in SML

查看:57
本文介绍了在 SML 中生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从特定范围生成随机数,例如范围 [1, 100] 中的整数 34?

How can you generate a random number from a specific range, for example the integer 34 in the range [1, 100]?

我查看了 随机结构 但它没有不要给我我想要的,至少从我能理解的角度来看.

I looked at the Random structure but it doesn't give me what I want, at least from what I can understand.

推荐答案

我认为你必须像这样在给定的链接中使用 Random 结构......

I think you have to use the Random structure in the given link like this ...

- val nextInt = Random.randRange (1,100);
- val r = Random.rand (1,1);
- val x1 = nextInt r;
- val x2 = nextInt r;

这篇关于在 SML 中生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆