官术网_书友最值得收藏!

Methods to generate random Boolean values

There are two methods, pick and roll, both of which can be called with or without the argument. These methods must be called on the class name itself, not on the value of it or a variable.

When either pick or roll is called with no argument, they return a random value, either True or False. We can see that in the following code snippet:

say Bool.pick;
say Bool.roll;

When the methods are called with an integer argument, a list of random values is generated. The integer argument defines the number of elements in the list, but on top of that, the pick method adds its limitation and returns only unique values, which, in the case of the Bool class, is not more than two. Compare the results of the similar calls, as follows:

say Bool.pick(4); # (False True) or (True False)
say Bool.roll(4); # e.g. (False True False False)
主站蜘蛛池模板: 西畴县| 西平县| 湘潭县| 铜鼓县| 潞城市| 敖汉旗| 若尔盖县| 小金县| 桃江县| 武邑县| 洱源县| 浙江省| 吐鲁番市| 威海市| 星座| 岑巩县| 当阳市| 翁源县| 手游| 灵宝市| 三江| 清流县| 治县。| 庄浪县| 沂源县| 新郑市| 南开区| 恩施市| 西宁市| 重庆市| 榆林市| 壶关县| 怀远县| 通榆县| 手机| 民勤县| 贺兰县| 昌宁县| 南江县| 赤壁市| 蒲江县|