summaryrefslogtreecommitdiff
path: root/src/hitomezashi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/hitomezashi.rs')
-rw-r--r--src/hitomezashi.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/hitomezashi.rs b/src/hitomezashi.rs
index da6e296..d5aa417 100644
--- a/src/hitomezashi.rs
+++ b/src/hitomezashi.rs
@@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use rand::Rng;
+use rand::distributions::{Bernoulli, Distribution};
const TRANSPARENT_SQUARE: char = ' ';
const OPAQUE_SQUARE: char = '█';
@@ -32,17 +32,18 @@ pub fn hitomezashi(width: usize, height: usize, skew: Option<f32>) {
};
let mut rng = rand::thread_rng();
+ let brn = Bernoulli::new(skew).unwrap();
let init_bit: bool = rng.gen::<bool>();
let mut row_bits: Vec<bool> = Vec::with_capacity(height - 1);
let mut col_bits: Vec<bool> = Vec::with_capacity(width - 1);
for _ in 0..(height - 1) {
- row_bits.push(rng.gen_bool(skew));
+ row_bits.push(brn.sample(&mut rng));
}
for _ in 0..(width - 1) {
- col_bits.push(rng.gen_bool(skew));
+ col_bits.push(brn.sample(&mut rng));
}
// each new row of the pattern depends on the bits directly above it