Quantum and atmospheric randomness should be 1-based #9
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: zzkt/i-ching#9
Loading…
Reference in a new issue
No description provided.
Delete branch "patch-1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add 1, as with calls to (random)
Thanks for the patch. I assume you got an out of range error somewhere? The current
ert
tests probably won't catch it, so can you let me know how it surfaced?The
i-ching-r64
function should return a number from 1 to 64. The request params are?num=1&min=1&max=64&base=10
if you are seeing an off-by-1 there, it could be the API call and would be useful to see a test case.The
i-ching-q64
looks like it could be returning 0-63 but I'll have to take a closer look (requests are rate limited)looks like
i-ching-r64
is behaving as expected (after a few thousand API calls..)on the other had
i-ching-q64
...{"type":"string","length":1,"size":1,"data":["00"],"success":true}
Interesting; on my machine I observe i-ching--three-coins sometimes returning nil with either atmospheric or quantum randomness. The path is something like this:
do this 3 times and 'result' in i-ching--three-coins is 3, which makes the pcase in there return nil.
I think the behaviour is different if you call (i-ching-random 64) (if the contract on q-64 or r-64 is 1-based) than if you call with n /= 64. The integer division in the other branches (where n isn't 64) will always return zero - n-1 rather than 1-n, because f.e. (/ 1 4) => 0. I might be missing something though?
Another thing that could go in i-ching-random would be
Which would guarantee an outcome that is in range so long as the randomness source does return an integer.
Ah so thinking about this more my diagnosis was wrong and the code I suggest above is a proper fix; it's the division not the 1- or 0- basis of the methods.
Thanks again @larkery it should be fixed with ab9eaa4
Pull request closed