diff options
author | Gabriel Dos Reis <gdr@axiomatics.org> | 2015-12-31 14:56:12 -0800 |
---|---|---|
committer | Gabriel Dos Reis <gdr@axiomatics.org> | 2015-12-31 14:56:12 -0800 |
commit | f51aee83708673ef9941174951bec9aee80cb03c (patch) | |
tree | 4d8cfccd653dfa09819234bc61a8775091e4f1e6 /src/algebra/permgrps.spad.pamphlet | |
parent | 039d244dbef31e4ca6d34d2cf42b58b41a572884 (diff) | |
download | open-axiom-f51aee83708673ef9941174951bec9aee80cb03c.tar.gz |
Avoid modulus bias in 'random()' usage.
Diffstat (limited to 'src/algebra/permgrps.spad.pamphlet')
-rw-r--r-- | src/algebra/permgrps.spad.pamphlet | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/algebra/permgrps.spad.pamphlet b/src/algebra/permgrps.spad.pamphlet index 39a9db79..652d4dbd 100644 --- a/src/algebra/permgrps.spad.pamphlet +++ b/src/algebra/permgrps.spad.pamphlet @@ -272,16 +272,16 @@ PermutationGroup(S:SetCategory): public == private where ranelt ( group : L V NNI , word : L L NNI , maxLoops : I ) : REC3 == -- generate a "random" element numberOfGenerators := # group - randomInteger : I := 1 + (random()$Integer rem numberOfGenerators) + randomInteger : I := 1 + random(numberOfGenerators)$Integer randomElement : V NNI := group.randomInteger words := nil()$(L NNI) if wordProblem then words := word.(randomInteger::NNI) if positive? maxLoops then - numberOfLoops : I := 1 + (random()$Integer rem maxLoops) + numberOfLoops : I := 1 + random(maxLoops)$Integer else numberOfLoops : I := maxLoops while positive? numberOfLoops repeat - randomInteger : I := 1 + (random()$Integer rem numberOfGenerators) + randomInteger : I := 1 + random(numberOfGenerators)$Integer randomElement := times ( group.randomInteger , randomElement ) if wordProblem then words := append ( word.(randomInteger::NNI) , words) numberOfLoops := numberOfLoops - 1 @@ -651,11 +651,11 @@ PermutationGroup(S:SetCategory): public == private where maximalNumberOfFactors < 1 => 1$(PERM S) gp : L PERM S := group.gens numberOfGenerators := # gp - randomInteger : I := 1 + (random()$Integer rem numberOfGenerators) + randomInteger : I := 1 + random(numberOfGenerators)$Integer randomElement := gp.randomInteger - numberOfLoops : I := 1 + (random()$Integer rem maximalNumberOfFactors) + numberOfLoops : I := 1 + random(maximalNumberOfFactors)$Integer while positive? numberOfLoops repeat - randomInteger : I := 1 + (random()$Integer rem numberOfGenerators) + randomInteger : I := 1 + random(numberOfGenerators)$Integer randomElement := gp.randomInteger * randomElement numberOfLoops := numberOfLoops - 1 randomElement |