April 6th, 2003, 02:00 PM
random number but NOT x
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.
April 6th, 2003, 02:55 PM
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
1,2,3, (4+1)=5 ..... (9+1)-10
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.
April 6th, 2003, 06:54 PM
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.
April 7th, 2003, 05:54 PM
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.
A = Random 1 to 10
Loop Until A <> 4
April 7th, 2003, 05:58 PM
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,