April 6th, 2003, 02:00 PM

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
April 6th, 2003, 02:55 PM

REAL RANDOM IS MEANINGLESS IN PROGRAMMING,
most pseudorandom generators are timerandom, 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=101
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 01, 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 timerandom functions.
No sign
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

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.
April 7th, 2003, 05:58 PM

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