Skip to content

Commit 5c400fd

Browse files
committed
Fixed PMComplex class >> random
1 parent a5ddeea commit 5c400fd

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/Math-Complex/PMComplex.class.st

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ PMComplex class >> one [
102102

103103
{ #category : #'*Math-Complex' }
104104
PMComplex class >> random [
105-
"Answers a random number with abs between 0 and 1."
106-
107-
^ self abs: 1.0 random arg: 2 * Float pi random
105+
"Answers a random number with abs between 0 and 1."
106+
| random |
107+
random := Random new.
108+
109+
^ self
110+
abs: random next
111+
arg: 2 * (random nextBetween: 0 and: Float pi)
108112
]
109113

110114
{ #category : #'instance creation' }

src/Math-Complex/PMComplex.extension.st

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@ PMComplex >> productWithVector: aVector [
1717
^ aVector collect: [ :each | each * self ]
1818
]
1919

20-
{ #category : #'*Math-Complex' }
21-
PMComplex class >> random [
22-
"Answers a random number with abs between 0 and 1."
23-
24-
^ self abs: 1.0 random arg: 2 * Float pi random
25-
]
26-
2720
{ #category : #'*Math-Complex' }
2821
PMComplex >> random [
2922
"analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced."
3023
^ self class random * self
3124

3225
]
3326

27+
{ #category : #'*Math-Complex' }
28+
PMComplex class >> random [
29+
"Answers a random number with abs between 0 and 1."
30+
| random |
31+
random := Random new.
32+
33+
^ self
34+
abs: random next
35+
arg: 2 * (random nextBetween: 0 and: Float pi)
36+
]
37+
3438
{ #category : #'*Math-Complex' }
3539
PMComplex >> subtractToPolynomial: aPolynomial [
3640
^ aPolynomial addNumber: self negated

0 commit comments

Comments
 (0)