News for hackers. Stuff that matters.
Re:How expensive is integer-overflow trapping in C++? by bregma on Thursday September 24, 2020 @07:01AM (#24577351)
Huh. That would make classic LCG PRNGs pretty useless. I guess it's "safer" in that it prevents rare dangerous edge cases at the expense of common everyday safe operations, but that's a tradeoff.
Re:How expensive is integer-overflow trapping in C++? by twic on Thursday September 24, 2020 @07:09AM (#24577390)
For your LCG you would use an explicitly wrapping type: https://doc.rust-lang.org/std/num/struct.Wrapping.html
Re:How expensive is integer-overflow trapping in C++? by OskarS on Thursday September 24, 2020 @07:14AM (#24577429)
If you want the wrapping behaviour (like with an LCG), you can prepend the operator with an ampersand(i.e &+ instead of +).
Re:How expensive is integer-overflow trapping in C++? by masklinn on Thursday September 24, 2020 @11:07AM (#24579300)
As hinted in my comment, Swift provides overflowing operators. You would implement your PRNG using those.