Comments (4)
That looks much better. I think there are still a couple of small mistakes, though.
On line 3168, the second argument to random-int
should be #x80000000
(231), not #x7FFFFFFF
(231 - 1), because random-int
returns a random number strictly less than its argument, and you want it to be able to return any 31-bit number, including the one that's all 1s.
Also, you can avoid some unnecessary calls to random-int
if you let y
be (- x 1)
and then use y
instead of x
throughout the computation of maybe-result
on lines 3160 - 3170. For example, if x
is 231, you need 31 random bits, so it's sufficient to call random-int
once, but the current code calls it at least twice (more if maybe-result
turns out to be too big).
from chezscheme.
I'm not entirely sure I'm right, but here are my thoughts.
random-integer
is supposed to return a number strictly less than x
. So (- x 1)
(i.e., y
) is the largest number it could return. So (integer-length y)
(i.e., len
) is how many bits you need from random-int
.
During the last iteration of the loop, when len
< 32, the most significant bits of y
(i.e., z
) are the largest value that the corresponding bits of maybe-result
should be allowed to have. And in order to get a random number that might be that large, you need to pass (+ z 1)
to random-int
, because it also returns a number strictly less than its argument.
So I think your current code is correct.
from chezscheme.
Thanks for the report!
from chezscheme.
Thank you for your analysis and help! I've pushed another attempt, and hopefully I understood you correctly about (- x 1)
. (I think I understand why that works, but I am not sure I have it right.)
from chezscheme.
Related Issues (20)
- Should `make test` use jobserver parallelism? HOT 6
- Intermittent crash in `make test` HOT 2
- `makefiles/boot.zuo`'s `main` calls `cross-build-boot` incorrectly HOT 3
- Why is `main.o` installed? HOT 3
- Bug in fixnum arithmetic HOT 1
- bytevector-reference-ref & set! fail to correctly check size of bytevectors smaller than ptr-bytes - 1 HOT 1
- Warnings from GCC `-fanalyzer`
- chezscheme 10 cannot be built from tarball HOT 1
- Non-tail calls to errorf sometimes treated as tail calls with debug-level 2 HOT 5
- weird cond expansion HOT 8
- a few questions regarding packaging chez-scheme HOT 6
- [PATCH] Update user's guide link in README HOT 1
- Bug in V format prefix parameter HOT 1
- native eol style HOT 4
- error: use of unknown builtin '__builtin_add_overflow' HOT 1
- How to cross compile on macOS for a different macOS architecture HOT 3
- Build fails if I set CC_FOR_BUILD HOT 1
- set! creates new bindings HOT 2
- Build/Embed Chez Scheme with larger C/C++ program HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chezscheme.