Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 6th, 2003, 02:00 PM
webmonkey's Avatar
webmonkey webmonkey is offline
Web Ape
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 7 webmonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old April 6th, 2003, 02:55 PM
tony825 tony825 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Greece
Posts: 63 tony825 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #3  
Old April 6th, 2003, 06:54 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #4  
Old April 7th, 2003, 05:54 PM
defjamninja defjamninja is offline
Overly white
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Fresno, CA
Posts: 83 defjamninja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #5  
Old April 7th, 2003, 05:58 PM
webmonkey's Avatar
webmonkey webmonkey is offline
Web Ape
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 7 webmonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > random number but NOT x


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT