Description
Read
returns byte sequence that depends on the buffer length. That's because Rand
uses Int63
value to produce 7 random bytes and throws away unused bits from Int63
when done with the particular call. Next call always starts with fresh Int63
leaving "gap" from previous Read
if it was not finished on 7-bytes boundary.
Therefore, you can't fix seed and read pseudo-random bytes deterministically without fixing buffer size.
Proposed fix
My proposal is to keep unused Int63
reminder in the Rand
struct. It let us fix the issue and still have the same bytes from the first Read
call as we have now. The performance hit is minimal also. The downside is an extra state in Rand
struct.
One of the other options is to use only single byte from each Int63
call. No state in Rand
but the 2x-4x performance hit.
- What version of Go are you using (
go version
)?
go version devel +f3d5478 Fri Jun 17 19:15:29 2016 +0000 linux/amd64
- What operating system and processor architecture are you using (
go env
)?
GOARCH="amd64"
GOOS="linux"
- What did you do?
This is play-adopted unit-test usingtesting/iotest
that fails: https://play.golang.org/p/dbz-VlFPCa - What did you expect to see?
The same random bytes stream no matter read buffer size used.