The same random numbers

Discussion in 'Questions (Windows Mobile)' started by LineCutter, Oct 14, 2008.

  1. LineCutter

    LineCutter Active Member Licensed User

    I might have missed this, but is there a way to specify a seed value to the rnd() function so that the same pseudo-random sequence is generated each time?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can do it with the Door library:
    Code:
    Sub Globals
        
    'Declare the global variables here.

    End Sub

    Sub App_Start
        Random.New1(
    False)
        Seed.New1(
    1)
        Seed.SetValue(
    0,75,"System.Int32"'Set the seed value
        Random.CreateNew2("System.Random",Seed.Value)
        
        
    Msgbox(MyRnd(0,10))
        
    Msgbox(MyRnd(0,10))
    End Sub

    Sub MyRnd(Minimum, Maximum)
        
    Return Random.RunMethod3("Next",Minimum,"System.Int32",Maximum,"System.Int32")
    End Sub
     

    Attached Files:

  3. LineCutter

    LineCutter Active Member Licensed User

    Thanks. That helps me create a password for the crypto question that agraham helped me with. Since it won't be physically present in the code it'll be that little bit harder for the casual hacker to bypass.
    Code:
    AF0="A1B2C3D4E5F67890"
        n=
    ""
        
    For i = 0 To 64
     n=n&StrAt(AF0,Random.RunMethod3(
    "Next",0,"System.Int32",StrLength(AF0),"System.Int32"))
        
    Next
     
  4. agraham

    agraham Expert Licensed User

    That's a good idea! Why not take it a bit further and generate the characters directly? In this case printable ASCII ones. As an aside why 65 characters in n?

    Code:
    n=""
    For i = 0 To 64
       n=n&
    Chr(Random.RunMethod3("Next"33"System.Int32"127"System.Int32")))
    Next
     
  5. LineCutter

    LineCutter Active Member Licensed User

    The code was from an "obfuscate as hex values" routine from a test program, hence the limited characters used.

    As for 65 values... well I'm clearly not a coder yet! :sign0148:
    (Although it was an arbitrary number the intention was for 64 characters, regardless of the fact that they would then go through the MD5 -> DES.key processing you help me with a few days back)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice