Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 6th, 2003, 03:00 PM
 webmonkey
Web Ape

Join Date: Mar 2003
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
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
April 6th, 2003, 03:55 PM
 tony825
Contributing User

Join Date: Jan 2003
Location: Greece
Posts: 63
Time spent in forums: < 1 sec
Reputation Power: 11
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

#3
April 6th, 2003, 07:54 PM
 balance
.

Join Date: Dec 2002
Posts: 296
Time spent in forums: < 1 sec
Reputation Power: 11
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.

#4
April 7th, 2003, 06:54 PM
 defjamninja
Overly white

Join Date: Mar 2003
Location: Fresno, CA
Posts: 83
Time spent in forums: < 1 sec
Reputation Power: 11
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.

#5
April 7th, 2003, 06:58 PM
 webmonkey
Web Ape

Join Date: Mar 2003
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
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

 Viewing: Dev Shed Forums > Programming Languages - More > Software Design > random number but NOT x