Oxygen Basic
		Programming => Problems & Solutions => Topic started by: Frankolinox on October 28, 2014, 01:51:24 AM
		
			
			- 
				my question: how to set a randomize factor for this six / seven balls (numbers). in my case the numbers are fix and always the same...
  '
  ' lotto script example by frank brĂ¼bach (frankolinox) october 2014, oxygen basic :)
  ' demo 1
  '
  $ filename "t.exe"
  includepath "$/inc/"
  '#include "RTL32.inc"
  '#include "RTL64.inc"
  #include "MinWin.inc"
  '#lookahead ' for procedures
 s=error()
  '
  if s then
    print s
    end
  end if
indexbase 1
sys seed,i,temp
dim Lotto(49) as long
dim Lottonumbers(7) as long
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 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 
' lottonumber = 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
for i = 1 to 49
    Lotto(i) = 1
next
i = 1
'------------- how to set a randomize timer -------------- ?
'RANDOMIZE
'------------- how to set a randomize timer -------------- ?
DO
temp = rnd(1,49)
if Lotto(temp) = 1 THEN
    Lottonumbers(i) = temp
    Lotto(temp) = 0
'INCR i
i++
end if
'LOOP UNTIL i > 7
 if i>7 then exit do
end do 
print " Your Lotto numbers are: "
for i = 1 to 6
print "Ball "+i+" "+str(LottoNumbers(i))
next 
print "- Push key for extra number: -"
'waitkey
print " And the extranumber is : "  + str(LottoNumbers(7))
print "end of lottonumber short example, oxygen basic"
'waitkey
do my a favour: hi all after a while of distance, I hope that the always lovely and overwhealming nice guy he's not programming with oxygen at all can miss my post in general and stay at another places here and cast away his characterless dirt to other people at this board (and I can fight basck, that's no problem for me)  so I can go on programming with oxygen basic and don't like to struggle always with jaleously kindergarten behaviour and bad attitudes ... :)
regards, frank
			 
			
			- 
				Hi Frank,
As Peter posted just before me:
! GetTickCount lib "kernel32.dll" () as sys
seed=GetTickCount 'randomize
I will include GetTickCount in the next MinWin.inc
			 
			
			- 
				Hi Charles,
Just FYI: rdseed/rdrand: super duper randomiser for Intel based CPU's here (http://www.fbsl.net/phpbb2/viewtopic.php?f=33&t=3039#p10600).
			 
			
			- 
				thanks for help peter, charles... and
! GetTickCount Lib "kernel32.dll" () As Long
seed = GetTickCount()  'Randomize
that trick I haven't had in my mind. nice day.
regards, frank
			 
			
			- 
				Mike,
Yes, arrays of random numbers, can be produced very efficiently. Using the rand algorithm above:
'ARRAY OF RANGED RANDOM NUMBERS
include "$/inc/console.inc"
! GetTickCount lib "kernel32.dll" () as long
long seed=GetTickCount 'randomize
function mrand(long z1,z2,*p,n)
===============================
mov ecx,n
addr esi,p
mov edi,seed
sub esi,4
(
 add esi,4
 dec ecx
 jl exit
 mov eax,z2
 sub eax,z1
 inc eax
 imul edx,edi,0x8088405
 inc edx
 mov edi,edx
 mul edx
 add edx,z1
 mov [esi],edx
 repeat
)
mov seed,edi
end function
long ra[1000] : mrand(1,100,ra,1000)
for i=990 to 1000 : printl ra[i] : next
waitkey
In Oxygen, the available registers are: eax,ecx,edx,esi,edi
and the ones that must be preserved: ebx,esp,ebp