Author Topic: rnd(a,b) command?  (Read 8355 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
Re: rnd(a,b) command?
« Reply #30 on: April 12, 2013, 09:25:05 AM »
Aurel ,

here it is with basic and small asm code
Code: [Select]
===============================
' Aurel's function with basic
===============================
Function B_Rand(sys z1, z2) as sys
  int Lex,Led
  Lex = z2
  Lex = Lex - z1
  Lex = Lex + 1
  Led = seed * 0x8088405
  Led = Led + 1
  seed = Led
  mov eax , Lex
  mul edx
  Lex = edx + z1
  return Lex
End Function

 

Charles Pegge

  • Guest
Re: rnd(a,b) command?
« Reply #31 on: April 12, 2013, 07:38:46 PM »
We can get close to an equivalent  Basic rand :)

Peter's Orginal:


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


Intermediate:

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



Basic:

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,100 '39
seed=12345 : print rand 1,100 '39
seed=12345 : print brnd 1,100 '39

Charles



Aurel

  • Guest
Re: rnd(a,b) command?
« Reply #32 on: April 12, 2013, 11:18:05 PM »
But Charles...
your code always return 1

Code: [Select]
function brnd(sys z1,z2) as sys
sys seed
seed*=0x8088405+1
eax=z2-z1+1 : mul seed
return edx+z1
end function

print brnd(1,100)

Aurel

  • Guest
Re: rnd(a,b) command?
« Reply #33 on: April 13, 2013, 12:14:43 AM »
Charles did you ever see something like this :
Quote
This isn't asm, but works fine in vb. You get the idea.

Dim startIndex As New String("1234567890")
Dim random As New Random
Dim startIndex1 As New String("0987654321")
Dim random1 As New Random
startIndex = random.Next(startIndex)
startIndex1 = random1.Next(startIndex1)
Dim str1 As String = startIndex
Dim str2 As String = startIndex1
Dim str3 As String = (str1 + str2).Substring(0, 10)
TextBox2.Text = str3
End SubEnd Class

Charles Pegge

  • Guest
Re: rnd(a,b) command?
« Reply #34 on: April 13, 2013, 01:01:43 AM »
Hi Aurel, seed has to be global, not defined inside the brnd function. (sys seed)

Aurel

  • Guest
Re: rnd(a,b) command?
« Reply #35 on: April 13, 2013, 02:41:24 AM »
Quote
Hi Aurel, seed has to be global,
Ok ...
But still return 1

Code: [Select]
sys seed

function brnd(sys z1,z2) as sys
seed*=0x8088405+1
eax=z2-z1+1 : mul seed
return edx+z1
end function

print brnd(1,100)

Charles Pegge

  • Guest
Re: rnd(a,b) command?
« Reply #36 on: April 13, 2013, 02:48:00 AM »
A seed of 0 wont work. You need to start with a large seed to saturate eax.

Frankolinox

  • Guest
Re: rnd(a,b) command?
« Reply #37 on: April 13, 2013, 02:51:22 AM »
aurel take some simple values for seed and try the example again with for example

seed=12345
Code: [Select]
sys seed=12345

function brnd(sys z1,z2) as sys
seed*=0x8088405+1
eax=z2-z1+1 : mul seed
return edx+z1
end function

print brnd(1,100)
print brnd(1,100)

so you will get different values.

@charles: very good your short rnd code example ;) for my openGL fog test I've used longer rand() function and that's working very fine there.

frank

Aurel

  • Guest
Re: rnd(a,b) command?
« Reply #38 on: April 13, 2013, 02:53:34 AM »
Ahhh..oh my i see now..
this work...
Code: [Select]
Declare Function GetTickCount   Lib "kernel32.dll" () As Int
sys seed
seed = GetTickCount
function brnd(sys z1,z2) as sys
seed*=0x8088405+1
eax=z2-z1+1 : mul seed
return edx+z1
end function

print brnd(1,100)