包容与排他的区别? [英] Difference between inclusive and exclusive?

查看:195
本文介绍了包容与排他的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这是一个简单的概念,但我遇到了包容性和排他性问题:特别是关于随机数生成器。

I feel like it's a simple concept, but I'm having trouble with inclusive and exclusive: particularly concerning random number generator.

例如,如果我想要一个值2-8(包括2和8),这将是包容性,正确吗?

For instance, if I wanted a value 2-8 (including 2 and 8), that would be inclusive, correct?

该代码看起来如何?
这样的事情:
nextInt(8 - 2)+ 2; ?

And how would that code look? Something like this: nextInt(8 - 2) + 2; ?

推荐答案


例如,如果我想要一个值2-8(包括2和8) ,那将是包容性的,对吗?

For instance, if I wanted a value 2-8 (including 2 and 8), that would be inclusive, correct?

。包容性包括;独家排除。

Yes. Inclusive includes; Exclusive excludes.

范围 2-8 包含7个唯一值(2,3,4,5, 6,7,8);和 随机.nextInt(int) 排除 指定值。所以你想要像

The range 2-8 inclusive is 7 unique values (2,3,4,5,6,7,8); and Random.nextInt(int) excludes the specified value. So you want something like

Random rand = new Random();
int min = 2;
int max = 8;
// ...
int r = rand.nextInt((max - min) + 1) + min;

这篇关于包容与排他的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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