File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
src/Math-Core-Distribution Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,19 @@ Class {
1111 #category : #' Math-Core-Distribution'
1212}
1313
14+ { #category : #information }
15+ PMNormalDistribution class >> boxMullerTransform [
16+ |v1 v2 w y |
17+ [ v1 := Number random * 2 - 1 .
18+ v2 := Number random * 2 - 1 .
19+ w := v1 squared + v2 squared.
20+ w > 1 ] whileTrue.
21+ y := (w ln * 2 negated / w) sqrt.
22+ v1 := y * v1.
23+ NextRandom := y * v2.
24+ ^ v1.
25+ ]
26+
1427{ #category : #information }
1528PMNormalDistribution class >> distributionName [
1629
@@ -42,17 +55,11 @@ PMNormalDistribution class >> new: aNumber1 sigma: aNumber2 [
4255PMNormalDistribution class >> random [
4356 " Answer a random number distributed according to a (0,1) normal distribution."
4457
45- | v1 v2 w y |
58+ | v1 |
4659 NextRandom
4760 ifNil: [
48- " Use Box-Muller transform"
49- [ v1 := Number random * 2 - 1 .
50- v2 := Number random * 2 - 1 .
51- w := v1 squared + v2 squared.
52- w > 1 ] whileTrue.
53- y := (w ln * 2 negated / w) sqrt.
54- v1 := y * v1.
55- NextRandom := y * v2 ]
61+
62+ v1 := self boxMullerTransform ]
5663 ifNotNil: [ v1 := NextRandom .
5764 NextRandom := nil ].
5865 ^ v1
You can’t perform that action at this time.
0 commit comments