trying to implement Mersenne Twister

About Monkey 2 Forums Monkey 2 Programming Help trying to implement Mersenne Twister

This topic contains 6 replies, has 4 voices, and was last updated by  kanati 3 months, 1 week ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5635

    codifies
    Participant

    I want a repeatable sequence of numbers to do procedurally generated levels (I want to be sure of the same sequence regardless of OS or hardware)

    I’ve attempted to implement https://en.wikipedia.org/wiki/Mersenne_Twister but seem to be getting four distinct bands of values when I plot 1000 values in a spreadsheet

    anyone got any ideas what I’m doing wrong?

    [/crayon]
    #5636

    abakobo
    Participant

    Eeeks. That kind of bit shifting is so ugly..

    With a fast look I see that oldseed is sometimes a short and sometimes a uint.. Is it normal?
    In that kind of code we are supposed to see only unsigned things don’t we? (index i signed too)

    #5638

    codifies
    Participant

    ack I was trying it as short must have missed one, sadly that makes no difference to this issue I described? the index type doesn’t seem to be causing the issue either….

    out of interest why is bitshifting ugly?

    #5639

    codifies
    Participant

    BINGO!

    basically it was an issue with the order of precidence of operations, obviously things are evaluated differently to C / python….

    [/crayon]
    #15257

    kanati
    Participant

    Ah this brings back memories.  Wrote the twister into a dll for use with B+ and BMax back in the day because both created a different set depending on which CPU architecture you had (Well, on certain intels and certain AMDs they did).  Glad to see someone else decided to implement it in Monkey so I don’t have to.   😀

    #15258

    papgar
    Participant

    Ooh this is really important for procedural generation in games and getting consistent results from a seed.  How is the performance using this is it a ton slower than just rand or not too bad?

    #15259

    kanati
    Participant

    I haven’t tried codifies implementation of it but I wouldn’t imagine it to be significantly slower than the built in PRNG.  I know when I implemented it for blitzplus and blitzmax I saw no performance hit at all.  Though I will admit that I didn’t stress test it against Mark’s PRNG.  But it definitely gave consistent results across platforms.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.