Results 1 to 12 of 12
  1.    #1  
    I'm not sure if any of you have seen this thread. I know Scotty has. Anyways, I'm creating an app that will randomly change your ringtone after each call. The only thing I'm stuck on now is how to generate a random number, with the following stipulations...

    1. Number generated must be > 0 and < x
    2. Number generated must be a rounded number.

    Regarding #2, I know with Mortscript 4.01 Alpha 9 has this option Round( number ), but I was hoping it would be possible with prior releases.

    I was thinking of using Timestamp() somehow, but I'm unsure how to make it conform with #1. I suk at math
  2. #2  
    Well, managed to get in before the experts.


    n=12 'the number of files you wish to have randomized

    x=timestamp () 'the time stamp

    z=substr(x,9,2) 'grab the seconds from there

    r=z*n/100 'multiply the seconds by the number of files, then device by 100

    y= part (r,".",1)+1 'strip of the numbers after the decimal, to round it, add 1 to get the numbers to start at 1

    message (y) 'displays the number


    Surur
    Last edited by surur; 04/19/2007 at 03:39 PM.
  3.    #3  
    NICE! Thanks

    It will work, but the numbers coming up are always greater than the previosly generated, since it's using the seconds as part of the calculation. Although, it will work.
    Last edited by crazie.eddie; 04/19/2007 at 03:53 PM.
  4. #4  
    small modification

    n=6

    x=timestamp ()

    tp=substr(x,9,2)

    z=substr(tp,2,1) & substr(tp,1,1) #reverses the order of the digits so the seed number makes larger changes quicker (ie faster than every 10 seconds)

    r=z*n/100

    y= part (r,".",1)+1

    message (y)
  5.    #5  
    Awesome! Thanks again
  6. #6  
    Quote Originally Posted by surur View Post
    Well, managed to get in before the experts.


    n=12 'the number of files you wish to have randomized

    x=timestamp () 'the time stamp

    z=substr(x,9,2) 'grab the seconds from there

    r=z*n/100 'multiply the seconds by the number of files, then device by 100

    y= part (r,".",1)+1 'strip of the numbers after the decimal, to round it, add 1 to get the numbers to start at 1

    message (y) 'displays the number


    Surur
    Surur, not knocking your logic, but what was wrong with?

    random = ( Timestamp() MOD n ) + 1

    Z.
  7. #7  
    Quote Originally Posted by zbop View Post
    Surur, not knocking your logic, but what was wrong with?

    random = ( Timestamp() MOD n ) + 1

    Z.
    Yes, my way is a longer way to do the same thing. Thats why I tried to get in before the experts

    Surur
  8. #8  
    Quote Originally Posted by surur View Post
    Yes, my way is a longer way to do the same thing. Thats why I tried to get in before the experts

    Surur
    haha, well if any experts DO show up, be sure to let me know

    There's more than one way to skin a cat, nuthin wrong with that.

    BTW, it should be pointed out that either method is not random at all if (1) it is called in rapid succession, i.e. a loop, or if (2) the script is scheduled at a constant interval.
  9. #9  
    Quote Originally Posted by zbop View Post
    BTW, it should be pointed out that either method is not random at all if (1) it is called in rapid succession, i.e. a loop, or if (2) the script is scheduled at a constant interval.
    This is actually a very valid point, as I think crazy.eddie is thinking of running the script every 60 seconds, which will obviously result in a very fixed pattern. With the routine being called with a (presumably) randomly times phone call it makes much more sense.

    Surur
  10. #10  
    ask mortie for a RND function/feature in the next release. that's what lazy experts would do.
  11. #11  
    Apparently its implemented in the next version, but obviously wont be back-ported to older mortscript interpreters.

    Surur
  12.    #12  
    Quote Originally Posted by surur View Post
    Apparently its implemented in the next version, but obviously wont be back-ported to older mortscript interpreters.

    Surur
    Cool. I've registered at the forum the other day, but I haven't received a confirmation email yet, so I couldn't put any suggestions yet.

Posting Permissions