#1
  1. Web Ape
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    7
    Rep Power
    0

    Question random number but NOT x


    Hey all,

    Any ideas for an algorithm to generate a random number between a range, excluding one of the numbers in that range? For example, say the range is one to ten and the number I don't want to be chosen is 4?

    All help will be cherished forever.

    WebMonkey
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Greece
    Posts
    63
    Rep Power
    12
    REAL RANDOM IS MEANINGLESS IN PROGRAMMING,

    most pseudorandom generators are time-random, i have found sourses for online random generation with a random(g) function where g is the astrical dust of earth on the actual milisec or something like this dont ask me im not in the physics,..... just wanna say its more random and more relyable since its not "predicable".

    you may use a simple random prefixed function of any lanquedge.

    if you want to use those you can reduse Max by 1 and if output greater or equal with x increase by 1

    ie
    MAX=10-1
    random(MAX,FACTOR)
    if a>=4
    return a+1
    else
    return a

    1,2,3, (4+1)=5 ..... (9+1)-10

    int RAND(MAX,FACTOR)
    {
    return real_to_int (MAX*FACTOR)
    }
    //factor being a ! constand ! real number from 0-1, but this wont be real random since for each MAX you get everytime the same output

    even if you add the x as a factor ie 1/x=FACTOR you'll still get the same "random" number for each set (MAX,x)

    conclution: i cant think of a way to find a random number w/o a time var (or something almost random) and i dont think there is on thats why all programming languedges have time-random functions.
    No sign
  4. #3
  5. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    13
    software derived 'random' numbers are going to remain 'random' not random. doesn't matter which algorithm you use.

    you've got to get the random number from external or hardware sources. pgp, when requiring a random number, requires you to jiggle your mouse round for a while. maybe there's something in using the microphone on a computer? - noise. or the net? - there are i have heard true random number generators available via the net. also i thought that maybe www information itself could be used? information noise - i'm not sure about that idea, it's just a thought - probably quite a bad one - not sure.
  6. #4
  7. No Profile Picture
    Overly white
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Fresno, CA
    Posts
    83
    Rep Power
    12
    Code:
    Do
    A = Random 1 to 10
    Loop Until A <> 4
    So you would just use the random number generator of your language and if the result is 4 then do it again until it's not 4. Sure this is not going to be truly random but what else can you do.
  8. #5
  9. Web Ape
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    7
    Rep Power
    0

    Thumbs up Many Thanks


    Many thanks people,

    This has got me well on my way to generating the types of random numbers I'm after. (Also provided tinder for some interesting debates in lectures.)

    All the best,

    WebMonkey

IMN logo majestic logo threadwatch logo seochat tools logo