Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeStinckwich committed Apr 18, 2012
1 parent e20c89e commit 05f5598
Show file tree
Hide file tree
Showing 138 changed files with 445 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .filetree
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "packageExtension" : ".pkg" }
{ "packageExtension" : ".package" }
4 changes: 4 additions & 0 deletions Math.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"noMethodMetaData" : true,
"separateMethodMetaAndSource" : false,
"useCypressPropertiesFile" : true }
File renamed without changes.
3 changes: 3 additions & 0 deletions Math.package/BinomialGenerator.class/instance/generator..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
generator: aRandomNumberGenerator
rng := aRandomNumberGenerator
3 changes: 3 additions & 0 deletions Math.package/BinomialGenerator.class/instance/n..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
n: numberOfTrials
n := numberOfTrials
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!BinomialGenerator methodsFor: 'as yet unclassified'!
as yet unclassified
next
| x |
x := 0.
n timesRepeat: [ rng next <= p ifTrue: [ x := x + 1 ] ].
^ x! !
^ x
3 changes: 3 additions & 0 deletions Math.package/BinomialGenerator.class/instance/p..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
p: aProbability
p := aProbability
18 changes: 18 additions & 0 deletions Math.package/BinomialGenerator.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"category" : "Math-Random",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"n",
"p",
"rng" ],
"name" : "BinomialGenerator",
"pools" : [
],
"super" : "NumberGenerator",
"traitcomposition" : "{}",
"type" : "normal" }
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

!BinomialGeneratorTest methodsFor: 'tests'!
tests
testBinomialGeneratorWithSuccessProbabilityOfOneAlwaysReturnNumberOfTrials
| g numberOfTrials |
g := BinomialGenerator new.
Expand All @@ -12,4 +11,4 @@ testBinomialGeneratorWithSuccessProbabilityOfOneAlwaysReturnNumberOfTrials
g generator: LehmerRandom new.
self assert: g next = numberOfTrials.
g generator: MersenneTwisterRandom new.
self assert: g next = numberOfTrials! !
self assert: g next = numberOfTrials
16 changes: 16 additions & 0 deletions Math.package/BinomialGeneratorTest.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "Math-Random-Tests",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "BinomialGeneratorTest",
"pools" : [
],
"super" : "TestCase",
"traitcomposition" : "{}",
"type" : "normal" }
1 change: 1 addition & 0 deletions Math.package/ConstantGenerator.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A ConstantGenerator is not really a random number generator.
3 changes: 3 additions & 0 deletions Math.package/ConstantGenerator.class/instance/constant..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
constant: aConstant
constant := aConstant
3 changes: 3 additions & 0 deletions Math.package/ConstantGenerator.class/instance/next.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
next
^ constant
16 changes: 16 additions & 0 deletions Math.package/ConstantGenerator.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "Math-Random",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "SergeStinckwich 3/30/2010 15:31",
"instvars" : [
"constant" ],
"name" : "ConstantGenerator",
"pools" : [
],
"super" : "NumberGenerator",
"traitcomposition" : "{}",
"type" : "normal" }
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

!ConstantGeneratorTest methodsFor: 'as yet unclassified'!
as yet unclassified
testConstantGeneratorGenerateAlwaysTheSameValue
| g numberOfTrials |
g := ConstantGenerator new.
g constant: 1.
self assert: g next = g next.
self assert: g next = g next! !
self assert: g next = g next
16 changes: 16 additions & 0 deletions Math.package/ConstantGeneratorTest.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "Math-Random-Tests",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "ConstantGeneratorTest",
"pools" : [
],
"super" : "TestCase",
"traitcomposition" : "{}",
"type" : "normal" }
Empty file.
3 changes: 3 additions & 0 deletions Math.package/GaussianGenerator.class/instance/generator..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
generator: aRandomNumberGenerator
rng := aRandomNumberGenerator
3 changes: 3 additions & 0 deletions Math.package/GaussianGenerator.class/instance/initialize.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
initialize
hasNextGaussian := false
3 changes: 3 additions & 0 deletions Math.package/GaussianGenerator.class/instance/mean..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
mean: aMeanValue
mean := aMeanValue
3 changes: 3 additions & 0 deletions Math.package/GaussianGenerator.class/instance/next.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
next
^ self nextGaussianNormalized * standardDeviation + mean
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

!GaussianGenerator methodsFor: 'as yet unclassified'!
as yet unclassified
nextGaussianNormalized
| x1 x2 w y1 y2 |
hasNextGaussian
Expand All @@ -15,4 +14,4 @@ nextGaussianNormalized
y1 := x1 * w.
y2 := x2 * w.
nextGaussian := y2.
^ y1! !
^ y1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
standardDeviation: aStandardDeviation
standardDeviation := aStandardDeviation
20 changes: 20 additions & 0 deletions Math.package/GaussianGenerator.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"category" : "Math-Random",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"rng",
"mean",
"standardDeviation",
"hasNextGaussian",
"nextGaussian" ],
"name" : "GaussianGenerator",
"pools" : [
],
"super" : "NumberGenerator",
"traitcomposition" : "{}",
"type" : "normal" }
Empty file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

!GaussianGeneratorTest methodsFor: 'as yet unclassified'!
as yet unclassified
checkDistributionOf: aGenerator withExpectedMeans: e andExpectedStandardDeviation: sd
| data m |
data := Set new.
10000 timesRepeat: [ data add: aGenerator next ].
m := 0.
data do: [ :each | m := each + m ].
m := m / data size.
self assert: e - m <= 0.2! !
self assert: e - m <= 0.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

!GaussianGeneratorTest methodsFor: 'as yet unclassified'!
as yet unclassified
testDistribution
| mean standardDeviation g |
mean := 147.
Expand All @@ -8,4 +7,4 @@ testDistribution
mean: mean;
standardDeviation: standardDeviation.
g generator: LCRandom new.
self checkDistributionOf: g withExpectedMeans: mean andExpectedStandardDeviation: standardDeviation! !
self checkDistributionOf: g withExpectedMeans: mean andExpectedStandardDeviation: standardDeviation
16 changes: 16 additions & 0 deletions Math.package/GaussianGeneratorTest.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "Math-Random-Tests",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "GaussianGeneratorTest",
"pools" : [
],
"super" : "TestCase",
"traitcomposition" : "{}",
"type" : "normal" }
3 changes: 3 additions & 0 deletions Math.package/LCRandom.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This uses a quick and dirty Linear Congruential generator.

LCRandom new next.
3 changes: 3 additions & 0 deletions Math.package/LCRandom.class/instance/initialize.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialize-release
initialize
" Private - Answer the receiver "
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!LCRandom methodsFor: 'accessing'!
accessing
next
"Private - Answer a pseudo-Random floating point number
between 0 and 1.
Uses a quick and dirty Linear congruential generator,"
^ self nextFloat! !
^ self nextFloat
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

!LCRandom methodsFor: 'accessing'!
accessing
nextFloat
"Private - Answer a pseudo-Random floating point number between 0 and 1.
Uses a quick and dirty Linear congruential generator,"

seed := self peekSeed.
^ seed / 120050.0! !
^ seed / 120050.0
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!LCRandom methodsFor: 'accessing'!
accessing
peek
"Private - Answer a pseudo-Random floating point number between 0 and 1.
Uses a simple, but fast, Linear Congruential generator."

^ self peekSeed / 120050.0! !
^ self peekSeed / 120050.0
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!LCRandom methodsFor: 'accessing'!
accessing
peekSeed
"Private - Answer the next Integer seed calculated
using a quick and dirty Linear congruential generator."

^ seed * 2311 + 25367 \\ 120050! !
^ seed * 2311 + 25367 \\ 120050
3 changes: 3 additions & 0 deletions Math.package/LCRandom.class/instance/zork.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
zork
^42
16 changes: 16 additions & 0 deletions Math.package/LCRandom.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "Math-Random",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "hfm 3/23/2009 21:22",
"instvars" : [
],
"name" : "LCRandom",
"pools" : [
],
"super" : "RandomGenerator",
"traitcomposition" : "{}",
"type" : "normal" }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests
testPeekAlwaysReplyTheSameValue
| g |
g := LCRandom new.
self assert: g peek = g peek
16 changes: 16 additions & 0 deletions Math.package/LCRandomTest.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "Math-Random-Tests",
"classinstvars" : [
],
"classtraitcomposition" : "{}",
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "LCRandomTest",
"pools" : [
],
"super" : "TestCase",
"traitcomposition" : "{}",
"type" : "normal" }
3 changes: 3 additions & 0 deletions Math.package/LehmerRandom.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This generator uses the Lehmer's Linear Congruential method.

LehmerRandom new next
3 changes: 3 additions & 0 deletions Math.package/LehmerRandom.class/instance/initialize.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialize-release
initialize
" Private - Answer the receiver "
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!LehmerRandom methodsFor: 'accessing'!
accessing
next
"Private - Answer a Random Float between 0 and 1.
Uses Lehmer's linear congruential method."

^ self nextFloat! !
^ self nextFloat
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!LehmerRandom methodsFor: 'accessing'!
accessing
nextFloat
"Private - Answer a Random Float between 0 and 1. Uses Lehmer's linear congruential method."

seed := self peekSeed.
^ seed / SmallInteger maxVal asFloat! !
^ seed / SmallInteger maxVal asFloat
5 changes: 5 additions & 0 deletions Math.package/LehmerRandom.class/instance/peek.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
peek
"Private - Answer a pseudo-Random floating point number between 0 and 1."

^ self peekSeed / SmallInteger maxVal asFloat
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

!LehmerRandom methodsFor: 'accessing'!
accessing
peekSeed
"Private - Answer the next Integer seed calculated using Lehmer's linear congruential
method. The seed is in the range 0..16r3FFFFFFF."

^ ( seed * 31415821 ) + 1 bitAnd: SmallInteger maxVal! !
^ ( seed * 31415821 ) + 1 bitAnd: SmallInteger maxVal
Loading

0 comments on commit 05f5598

Please sign in to comment.