- Perl 6 Deep Dive
- Andrew Shitov
- 159字
- 2021-07-03 00:05:53
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)
推薦閱讀
- Java范例大全
- Rust實戰
- Hands-On RESTful Web Services with Go
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- Active Directory with PowerShell
- Python語言實用教程
- 愛上micro:bit
- Learning AWS
- Java程序設計與項目案例教程
- SpringBoot從零開始學(視頻教學版)
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- Flask Web開發:基于Python的Web應用開發實戰(第2版)
- INSTANT Apache ServiceMix How-to
- 少兒編程輕松學(全2冊)
- 微信小程序開發邊做邊學(微課視頻版)