- 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)
推薦閱讀
- Django+Vue.js商城項目實戰
- 圖解Java數據結構與算法(微課視頻版)
- FFmpeg入門詳解:音視頻流媒體播放器原理及應用
- OpenCV 3和Qt5計算機視覺應用開發
- 從0到1:HTML+CSS快速上手
- JavaScript動態網頁開發詳解
- Java EE 7 Performance Tuning and Optimization
- Python數據結構與算法(視頻教學版)
- Mastering Backbone.js
- 軟件體系結構
- Clojure for Java Developers
- Spring 5 Design Patterns
- Go語言從入門到精通
- 微前端設計與實現
- Python Machine Learning Cookbook