Welcome to the TechSpot OpenBoards. Please read the FAQ if you have any questions. Sign up or Login to participate.
|
|||||||
Begin your free trial now
Pay-as-you-go options starting at $10/user/month
Pay-as-you-go options starting at $10/user/month
Programming help - random numbers
|
|
Thread Tools | Search this Thread |
|
#1
|
||||
|
||||
|
Programming help - random numbers
hi,
i have made a program that will generate a random number until the number i type is generated, but to make it faster i thought it would be helpful to stop the program going over numbers it has already generated, the problem is, i have no idea how to do this. please help, Thanks! lammie12345@yahoo.co.uk |
|
#2
|
||||
|
||||
|
what language?
PS > do yourself a favor and remove your email address from above post, this is a public webpage. |
|
#3
|
|||
|
|||
|
Quote:
Quote:
Maybe get some inspiration here: http://msdn.microsoft.com/library/de...mrandomize.asp |
|
#4
|
||||
|
||||
|
Well RBS, good point, unless of course his random number range is like 1 to 20.
I don't think you will "save time" by avoiding the numbers though. Think about it, MORE programming steps have to take place, as well as memory space. 1) You will have to store all the numbers previously chosen, meaning a database of sorts, and thus memory usage. 2) You will have to query this database to see if the current number matches a stored number. Thus processing power. 3) And lastly, the random number has ALREADY been selected, so why waste processing time to see if it's been chosen before? Just check the number against yours and move on. It's probably fastest the way you're doing it now. UNLESS, there is some long calculation performed on each number selected. In this case, checking the number, and thus avoiding a much more costly and redundant code, a check could be useful. So you have to weigh the 3 items above in terms of memory and processing, against the processing you do on each random number. And come to a conclusion of whether you really need to do this. So please answer the questions above, and enumerated here: What language? What is the range of random numbers? What kind of processing do you do on each number? |
|
#5
|
||||
|
||||
|
Unless you are working with a computer from 1970s it should have enough horsepower to generate reasonably random numbers in a blink and store at least thousands of them in a bit field (and reference that in a matter of milliseconds).
What language and what algorithms are you using? What exactly do you want to do? How about providing the source code here? |
|
|
|
#6
|
||||
|
||||
|
if the goal is a single digit random number, then the value of PI (circumference / diameter) to the maximum precision possible, is a great seed value.
however, that number (3.1416.....) clearly has repeating digits. Your therom may need to be reevaluated, depending upon your expected usage. |
|
#7
|
||||
|
||||
|
i think he wants to do integers here...
|
|
#8
|
|||
|
|||
|
what's the definition of a random number in programming anyway? I mean, if using algorythms, the number is newer really random - I know that's picking holes, but at the same time, it also means that theere must be a programmers definition of 'random'?
|
|
#9
|
||||
|
||||
|
Actually Spike, you're right, for most purposes, the built-in random generators in most basic languages are not very random. I read a big long article on the subject one time, heck if I remember now though.
I found this snippet while searching around: Quote:
|
|
#10
|
||||
|
||||
|
Modern operating systems usually provide number generation that is truely random for any practical purposes. The "randomness" is collected from peripheral devices like the network card, keyboard (user input is a very random thing - noone can produce the same keystrokes at millisecond accuracy), hard drives etc.
|
|
#11
|
|||
|
|||
|
Random numbers
Hi tomyas.
If I understand correctly... You want to create a program that generated a random number. For an example (between 0 and 1000). If you want to avoid generating the same number you should try the following... This is if I understand correctly... 1) create an array example: dim myarray(0 to 1000) as integer 2) generate a random number 3) Check the value on the array if myarray(random_number)=0 then 'this means the number was not previously generated 'now flag it... myarray(random_number)=1 else 'this means it was previously generated 'generate again end if Happy Programming... |
|
#12
|
|||
|
|||
|
programming languages usually have a built in radom number generator, ive used the one in c++ before, it gets the same random numbers every time, to get around this you can "seed" it with something to give it a different starting place and therefore different radom numbers. the easiest thing to do is use the system clock to seed the generator, which unless you got two computer in sync with eachother and got them to generate at the exact same second, you wouldnt get the same numbers....however you can always use something else to seed the generator. If you know how the generator works and you know exactly what is being put into it, you will be able to find out what the outcome will be, but the computer will do it alot faster than you and thats why it looks random.
|
|
#13
|
||||
|
||||
|
Is this thread's author going to give some feedback?
Chances are good he's already finished the program, distributed it, and you can find it at your local Walmart. lol Either that or Microsoft saw the monetary advantages of owning an app that makes random numbers, and so they bought him out and made sure he never programs again, thus why he can't comment here any more.
|
![]() |
| Similar Topics | ||||
| Topic | Replies | Forum | ||
please help me i cant write numbers
|
7 | Windows OS | ||
Confusing Ram Numbers
|
2 | Other Hardware | ||
Need to change IRQ numbers
|
4 | Windows OS | ||
IP Numbers
|
6 | Software Apps | ||
| Thread Tools | Search this Thread |
|
|
All times are GMT -4. The time now is 11:37 AM.



please help me i cant write numbers