Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Rnd assembler

IDKIDK Posts: 1,784Member
How should a random number generator function look like?
I just want to use it.

The one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

Comments

  • anthrax11anthrax11 Posts: 511Member
    : How should a random number generator function look like?
    : I just want to use it.
    :
    : The one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
    :

    I remembered, that there are many nice rnd number generators in fire routines, so I looked it up:
    This proc has been taken from the following page: http://www.programmershelp.co.uk/showcode.php?e=496

    [code]Random PROC
    MOV AX, Seed ; Move the seed value into AX
    MOV DX, 8405H ; Move 8405H into DX
    MUL DX ; Put 8405H x Seed into DX:AX
    INC AX ; Increment AX
    MOV Seed, AX ; We have a new seed
    RET
    Random ENDP
    [/code]
    It seems to work pretty good with my own fire routines btw:)
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : How should a random number generator function look like?
    : : I just want to use it.
    : :
    : : The one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
    : :
    :
    : I remembered, that there are many nice rnd number generators in fire routines, so I looked it up:
    : This proc has been taken from the following page: http://www.programmershelp.co.uk/showcode.php?e=496
    :
    : [code]Random PROC
    : MOV AX, Seed ; Move the seed value into AX
    : MOV DX, 8405H ; Move 8405H into DX
    : MUL DX ; Put 8405H x Seed into DX:AX
    : INC AX ; Increment AX
    : MOV Seed, AX ; We have a new seed
    : RET
    : Random ENDP
    : [/code]
    : It seems to work pretty good with my own fire routines btw:)
    :
    [blue]Here is another algorithm:
    [code]
    // one time initialization at the beginning of a program
    seed = milliseconds from timer

    // Function entrance
    random = (A*seed + B) mod 1024
    seed = random
    return random
    // Function exit
    [/code]

    A and B are odd values - they should be experimented with, so the whole sequence of number will include all valies in range [0..1023][/blue]

  • anthrax11anthrax11 Posts: 511Member
    : : : How should a random number generator function look like?
    : : : I just want to use it.
    : : :
    : : : The one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
    : : :
    : :
    : : I remembered, that there are many nice rnd number generators in fire routines, so I looked it up:
    : : This proc has been taken from the following page: http://www.programmershelp.co.uk/showcode.php?e=496
    : :
    : : [code]Random PROC
    : : MOV AX, Seed ; Move the seed value into AX
    : : MOV DX, 8405H ; Move 8405H into DX
    : : MUL DX ; Put 8405H x Seed into DX:AX
    : : INC AX ; Increment AX
    : : MOV Seed, AX ; We have a new seed
    : : RET
    : : Random ENDP
    : : [/code]
    : : It seems to work pretty good with my own fire routines btw:)
    : :
    : [blue]Here is another algorithm:
    : [code]
    : // one time initialization at the beginning of a program
    : seed = milliseconds from timer
    :
    : // Function entrance
    : random = (A*seed + B) mod 1024
    : seed = random
    : return random
    : // Function exit
    : [/code]
    :
    : A and B are odd values - they should be experimented with, so the whole sequence of number will include all valies in range [0..1023][/blue]
    :
    :
    [green]
    The CS register makes a pretty good seed number as well, because your program is loaded to where there is free space in the memory(which can be almost anywhere). I usually use CS in asm and the timer in Basic.[/green]
  • IDKIDK Posts: 1,784Member
    [b][red]This message was edited by IDK at 2005-10-12 7:47:10[/red][/b][hr]
    I found the easiest method, it isn't very random, but enough I think,
    Read the lowest byte of what the real timer function returns.

    When I need a more complex function, I'll use your func's

    The one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]



Sign In or Register to comment.