SPONSORS:






User Tag List

Results 1 to 6 of 6
  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    Paris (France)
    Posts
    182
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating Random Integer

    Is there a better way to generate a random integer than SilkTest's RandInt() function? I need true random numbers that going through a loop will give a diffrent random number each time. How RandInt does it is you get the same number on a fast loop.

    I did make a RandomInt() function (see below), which helps on general random numbers since it is using RandSeed(), but on a loop that just grabs some random numbers, I still get the same numbers.

    Anyone have a better way?



    ------------------
    David Genrich
    Icarian
    333 Moffett Park Drive
    Sunnyvale, CA 94089
    davidg@icarian.com



  2. #2
    AJ
    AJ is offline
    Moderator AJ's Avatar
    Join Date
    Jun 1999
    Location
    San Jose, CA
    Posts
    1,691
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Generating Random Integer

    Here's an idea... Only an idea though

    Try to have your function sleep a random time (1-3 seconds or so) and after the sleep call the RandInt () function.

    You sort of call the RandInt twice one in each other. that doubles your Randomness chances.

    Here's another idea:
    ------------------
    AJ Alhait
    BetaSoft Inc.


    [This message has been edited by AJ (edited 11-01-1999).]
    AJ Alhait
    BetaSoft Inc.

  3. #3
    jb
    jb is offline
    Junior Member
    Join Date
    Sep 1999
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Generating Random Integer

    Or you could use the RndSeed function and set the seed value to the current time (converted to an integer).

  4. #4
    Senior Member
    Join Date
    Jul 2002
    Location
    Paris (France)
    Posts
    182
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Generating Random Integer

    Did use the random seed with the time - the numbers stay the same if you put it through a 11 count loop. Tried doing just the seconds. Still not enough. the code above I am taking the seconds multiplied by the seconds. That works for generall use if I am picking slowly. But if I want to run a loop that just grabs 50 numbers, they will all be the same.

    The SilkTest Random algorthm is really bad. I understand that it isn't trully "random", it is a pseudo-random result set, but calling it several concutive time, using a random seed of seconds squared, one would think you could get somewhat diffrent numbers.

    I am currently looking for a good mathmatical equation to create my own RandInt() funtion.


    ------------------
    David Genrich
    Icarian
    333 Moffett Park Drive
    Sunnyvale, CA 94089
    davidg@icarian.com



  5. #5
    Senior Member
    Join Date
    Jul 2002
    Location
    Paris (France)
    Posts
    182
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Generating Random Integer

    OK, did some more testing on this and found I didn't really have a problem. In normal testing, I am using the RandomInt() function I posted above. This keeps the numbers from being the same each time I run the testcase. For running a loop that I was just many random integers, the default SilkTest RandInt() function with no RandSeed value applied will produce the desired randomness needed.



    ------------------
    David Genrich
    Icarian
    333 Moffett Park Drive
    Sunnyvale, CA 94089
    davidg@icarian.com



  6. #6
    Junior Member
    Join Date
    Nov 1999
    Location
    San Jose, CA 95130
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Generating Random Integer

    Do you know that if you're just grabbing the second part, you are not doing a good job of randomizing.

    Why don't you use the whole hours, minutes, and seconds? If you want to have more random, then you can modify the result number by itself, as you did in your original
    code.

    -Michael Hwee-


    [This message has been edited by admin (edited 11-03-1999).]

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 08:58 PM.

Copyright BetaSoft Inc.