Thread: /dev/urandom

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    17
    Rep Power
    0

    /dev/urandom


    Hi, how do I use /dev/urandom to generate a single number between 1-100? I can od /dev/urandom but it gives me an endless list of random numbers, I just want 1 between 1-100. How can I get that? Thanks.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    Use the modulo operator in your favourite programming language or utility.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    17
    Rep Power
    0
    Originally Posted by Scorpions4ever
    Use the modulo operator in your favourite programming language or utility.
    modulo: not found
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,636
    Rep Power
    1811
    What language are you using?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    17
    Rep Power
    0
    Just using the regular shell.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,636
    Rep Power
    1811
    It will be part of the standard Arithmetic operators:

    echo $(( 13 / 4 ))
    3
    echo $(( 13 % 4))
    1
    Thus 1 is the remainder of the integral division. You would need, in this case to do something like (assuming $rand_num contains your number obtained from /dev/urandom):

    Code:
    my_rand=$(( ( $rand_num % 100 ) + 1 ))
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo