wie funktioniert eigentlich random()
Verfasst: 09.11.2005 15:07
hm ich hab irgenwei gerade ncihts besseres zu tuen un dann komtm mir die Frage in den Kopf wie funktioneirt eigentlich Random() ?
Das deutsche PureBasic-Forum
https://www.purebasic.fr/german/
Code: Alles auswählen
OpenWindow(#PB_Any, 0, 0, Random(400)+100, Random(250)+100, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Testfenster")
Code: Alles auswählen
currentR = R
Prozedur Random
Global currentR
currentR = currentR % LUT(currentR % 256)
Return currentR
ProzedurEnde
LUT = (34, 46, 23, 62, ...)
Code: Alles auswählen
#m=100000000
#m1=10000
#b=31415821
i.l
Global a.l
N.l
Procedure mult(p.l,q.l)
p1.l
p0.l
q1.l
q0.l
p1=Int(p/#m1)
p0=p%#m1
q1=Int(q/#m1)
q0=q%#m1
ProcedureReturn (((p0*q1+p1*q0)%#m1)*#m1+p0*q0)%#m
EndProcedure
Procedure myrandom(r) ;r=max
a=(mult(a,#b)+1)%#m
ProcedureReturn Int((Int(a/#m1)*r)/#m1)+1 ;zahlen von 1 bis r
EndProcedure
N=10
a=Random(12135) ;seed
For i=1 To N
Debug myrandom(11)
Next
Code: Alles auswählen
Procedure.f mySin(x.f)
Protected res.f, sum.f, num.f, denom.f
; map x into [0, 2*PI[
x = x/(2*#PI)
x = x-Int(x)
sum = x*(2*#PI)
; do the taylor series approx
res = 0.0
num = -sum*sum
denom = 2.0
repeat
res = res + sum
sum = sum * num / (denom*denom+denom)
denom + 2.0
until abs(sum/res) < 1/100000
ProcedureReturn res
EndProcedure
Procedure.f myCos(x.f)
ProcedureReturn mySin(x + 0.5*#PI)
EndProcedure
Debug "Calculating the sine and cos using"
Debug "the taylor series approximation."
Debug "val := mySin(x) - sin(x):"
Debug "val := myCos(x) - cos(x):"
For i=0 to 20
bla.f = Random(100000)/1000.0 - 50.0
debug StrF(mySin(bla) - Sin(bla), 10)
debug StrF(myCos(bla) - Cos(bla), 10)
next
yap, so meinte ich das.Froggerprogger hat geschrieben:aber man könnte mit ihnen z.B. ein Array mit z.B. 3600 Werten (also für jedes Zehntelgrad ein Wert) zu Beginn des Programms erstellen.