Hi Charles I dont quite understand the rnd command Like this example
If you are using sys seed all is OK If I am using another variable the result is wrong or its depending of your asm Code Part? Its confusing me a little
'-- rnd questions
'
sys hobbit
sys seed
Function Rnd(sys z1,z2) as sys
pushad
sys rand
mov eax,z2
sub eax,z1
inc eax
imul edx,seed,0x8088405
inc edx
mov seed,edx
mul edx
add edx,z1
mov rand,edx
popad
Return rand
End Function
function rand(sys z1,z2) as sys
mov eax,z2
sub eax,z1
inc eax
imul edx,seed,0x8088405
inc edx
mov seed,edx
mul edx
add edx,z1
return edx
end function
function brnd(sys z1,z2) as sys
seed*=0x8088405+1
eax=z2-z1+1 : mul seed
return edx+z1
end function
seed=12345 : print rnd 1,10 '4
seed=12345 : print rand 1,100 '39
seed=12345 : print brnd 1,1000 '386
'
' 2
'
hobbit=12345 : print rnd 1,10 '3
dim myvalue as integer
myvalue=2024
'myvalue=int((6*rnd)+1) 'vb
myvalue=rnd 1,6 '1
print myvalue
Perhaps you have another o2 example at Hand
Regards frank
Hi Frank,
From inc\chaos.inc:
rnd() returns float values between -1.0 and 1.0
irnd(min,max) returns random integers between min and max
They are only pseudo-random, of course, just scrambled numbers, dependent on the initial seed value.
int seed=0x12345678
'
function Rnd() as float
=======================
Static As float f, d=1/0x7fffffff
mov eax,seed
inc eax
rol eax,13
xor eax,0xdab5ca3a
mov seed,eax
push eax
fild dword [esp]
pop eax
fmul dword d
fstp dword f
return f
end function
'ABS RANDOMISER
'
function arnd() as float
========================
return Abs(Rnd)
end function
function irnd(int z1, z2) as int
================================
mov eax,z2
sub eax,z1
inc eax
imul edx,Seed,0x8088405
inc edx
mov Seed,edx 'store new seed
mul edx 'multiply eax by edx
return edx+z1
end Function
Thank you Charles :)
Here a little example "lottery" 6 Out of 49 in Germany Name is "Lottozahlen"..
' lottery: germany, lottozahlen 6 out of 49 plus extraball
' oxygen, by frank bruebach, 14-2-2024
'
dim i, temp as long
dim Lotto(49) as long
dim Lotterynumbers(7) AS LONG
' lotterynumber = "lottozahlen", you draw six number of 49 possibilities, 6 numbers of 49 drop down of a sphere into glasses
' extranumber = after the drawing of six number you can get the 7th number as extranumber and earn more money
int seed=0x12345678
function Rnd() as float
=======================
Static As float f, d=1/0x7fffffff
mov eax,seed
inc eax
rol eax,13
xor eax,0xdab5ca3a
mov seed,eax
push eax
fild dword [esp]
pop eax
fmul dword d
fstp dword f
return f
end function
'ABS RANDOMISER
'
function arnd() as float
========================
return Abs(Rnd)
end function
function irnd(int z1, z2) as int
================================
mov eax,z2
sub eax,z1
inc eax
imul edx,Seed,0x8088405
inc edx
mov Seed,edx 'store new seed
mul edx 'multiply eax by edx
return edx+z1
end Function
'
'lottery begin --------------------------- //
'
for i = 1 to 49
Lotto(i) = 1
next
i = 1
'RANDOMIZE
arnd()
do
temp = irnd(1,49)
if Lotto(temp) = 1 then
Lotterynumbers(i) = temp
Lotto(temp) = 0
i++
endif
loop until i > 7
print " Your Lottery numbers are: "
for i = 1 to 6
print ("Ball "+i+" "+str(LotteryNumbers(i)))
next
print (" And the extranumber is : " + str(LotteryNumbers(7)))
print ("end of lotterynumber short script")
PS Charles its possible to make a fixed command in next oxygen Update for rnd irnd arnd ? Or I must Always use this construct ? :)
I'll think about it, Frank, but its all included in chaos.inc which in turn is included in the OpenGl Frameworks.
We might need a choice of random number for different applications.
oxygen programming technique question
hi charles, may I ask you how I can include a function as fixed command in oxygen?
something like this one?
'irnd 16 #sys#sys@0 sys 2560
int seed=0x12345678
function irnd(int z1, z2) as int
================================
mov eax,z2
sub eax,z1
inc eax
imul edx,Seed,0x8088405
inc edx
mov Seed,edx 'store new seed
mul edx 'multiply eax by edx
return edx+z1
end Function
I can suppose there's a lot of more to handle isn't it?
regards, frank
I don't want this inside o2 core yet but you can create your own .inc library of functions. They can be new functions or even override existing functions.
I understand No Problem Charles thx I will try to make an alternative way and try to implement a rnd2() or irnd2() and rgb() fixed command in oxygen I dont give Up ;)
I am studying also the freebasic source Code of oxygen 2016 and try to learn more about this topic
Nice wednesday