Replace hand-rolled chunks loop in `fill_bytes` with `chunks_exact_mut`

This issue has been created since 2021-11-19.

Both Mt::fill_bytes and Mt64::fill_bytes use a handrolled implementation of [u8]::chunks_exact_mut.

Replace these while loops with use of the ChunksExactMut iterator.

rand_mt/src/mt.rs

Lines 306 to 317 in 7123536

let mut left = dest;
while left.len() >= CHUNK {
let (next, remainder) = left.split_at_mut(CHUNK);
left = remainder;
let chunk: [u8; CHUNK] = self.next_u32().to_le_bytes();
next.copy_from_slice(&chunk);
}
let n = left.len();
if n > 0 {
let chunk: [u8; CHUNK] = self.next_u32().to_le_bytes();
left.copy_from_slice(&chunk[..n]);
}

rand_mt/src/mt64.rs

Lines 289 to 300 in 7123536

let mut left = dest;
while left.len() >= CHUNK {
let (next, remainder) = left.split_at_mut(CHUNK);
left = remainder;
let chunk: [u8; CHUNK] = self.next_u64().to_le_bytes();
next.copy_from_slice(&chunk);
}
let n = left.len();
if n > 0 {
let chunk: [u8; CHUNK] = self.next_u64().to_le_bytes();
left.copy_from_slice(&chunk[..n]);
}

lopopolo wrote this answer on 2021-11-19

boba includes some code that uses chunks_exact which gives an example of how we'd be able to poke at the remainder slice:

https://github.com/artichoke/boba/blob/63b3b3fe5814d2b8641b1769c4ca61ceaaeed5ea/src/lib.rs#L192-L216

More Details About Repo
Owner Name artichoke
Repo Name rand_mt
Full Name artichoke/rand_mt
Language Rust
Created Date 2020-03-14
Updated Date 2022-01-02
Star Count 8
Watcher Count 2
Fork Count 1
Issue Count 0

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Use the new-and-shiny regexes to improve examples/format.007 6 2016-08-26 2022-09-10
Introduce a Val::Bool type 8 2016-07-08 2022-09-10
Idea - Add support for many joystick 1 2020-09-28 2022-07-19
Photos and videos still taking up cloud space 4 2022-03-28 2022-08-15
with clause nested query. 0 2022-05-24 2022-08-27
After running the main.py , i got these errors 1 2021-07-09 2022-07-03
I'm getting a lot of errors! 1 2021-07-09 2022-07-03
go2sky-gRPC2021/06/22 21:35:34 reach max send buffer 1 2021-06-29 2022-08-26
TypeError: endswith first arg must be str or a tuple of str, not list 0 2021-07-08 2022-09-04
Allow users to spin up a WooCommerce testing environment 3 2022-07-12 2022-09-06
Unknown Firewall (585d1e9af) 0 2022-03-02 2022-09-24
Documentation request: Calling steps from step definitions 3 2022-01-26 2022-09-28
mapping over a field, changing its type? 0 2022-07-08 2022-08-20
GetDataOffestForAddress, but in C++ 0 2022-02-09 2022-07-20
Failed to resolve: com.github.YvesCheung.RollingText:RollingText:x.y.z 2 2021-12-23 2022-09-09
SABnzbd deletes music files that contain the string 'sample' 9 2022-09-17 2022-09-24
Request for a --file/--iso option, to write the result to a file/iso instead of only partition/device. Basically to convert the original UEFI iso to a Legacy type img/iso 0 2021-08-18 2022-08-31
Fee estimation endpoint? 4 2022-06-16 2022-09-05
`detect_fts()` identifies the wrong table if tables have names that are subsets of each other 3 2022-05-20 2022-09-18
[TRACKING] Libs Release 2 2022-09-21 2022-09-19
GMIC dialog no longer works, when I run the tool, I get a blank (white) GMIC dialog. 2 2020-10-03 2022-08-09
Cannot get script to write multiple pages to same CSV 0 2021-03-08 2022-09-25
Many features don't reset across different repositories 4 2022-07-13 2022-08-13
Underscore `_` as digit separator 1 2022-05-28 2022-08-21
Unable to download and access data. 3 2021-03-30 2022-09-08
Unable to configure xcodebuild.productName 3 2016-01-26 2022-08-25
[High] Cannot create columns or rows 2 2021-06-22 2022-09-10
Allow deletion without archiving for configured workspaces 1 2022-01-06 2022-09-02
Fix: Associate spans and events when it throws 0 2021-10-22 2022-09-28
GUI unresponsive / slow - ifconfig bg-job "hangs" 9 2021-11-10 2022-07-20
Wrong initial value (NaN) for prop "checked" for scheduled sending radio button 1 2022-05-16 2022-09-20
StartContinuousRecognitionAsync() only understands first sentence 3 2022-02-10 2022-09-21
Legacy Search Keyword - "message": "must not be empty" 0 2022-08-17 2022-08-20
Typo in Section 12.3.2 (p.386) 0 2021-08-04 2022-09-18
[NEW] Can old master(new slave) psync with new master(old slave) after failover when old master crashed? 0 2021-11-25 2022-08-01
The results (selection and highlight) should only reflect layers from the map 1 2021-09-30 2021-12-26
Cancel flag still creates flag 2 2021-08-30 2021-12-26
About pyotrch version 6 2022-07-15 2022-09-01
Provide code samples for iOS 1.0 blog 1 2022-08-15 2022-09-21
Queue triggered Azure function displays 'Critical availability error'. 6 2022-07-18 2022-09-19
InvalidTargetDataCheck should run for time series regression 0 2022-01-14 2022-08-28
Extension issue 0 2021-10-11 2022-01-14
SampleProject Error Upon Opening in Unity 15 2020-05-05 2022-09-24
Update the `changePassword` from api-client 1 2022-04-11 2022-09-15
light groups containing only light groups are unavailable after restarting the core 12 2021-08-10 2022-09-10
Getting false positives due to scanner taking wildcard in dependency version 5 2021-10-24 2022-07-20
RunInference: investigate adding optional batching flag 0 2022-06-14 2022-08-12
[Idea] Return YouTube's Dislike Count. 1 2021-11-22 2022-08-27
Semantic not built on Heroku 4 2016-03-01 2022-09-18
SQL Improvement 0 2021-09-02 2021-12-27