![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
To help Fall Back Son:
#include <dealwithrandomnumbergeneratinghardware.h>
int main(){ int randomyesthisreallyisrandom = getsomerandomnumberfromspecializedhardware(); }
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials. --WilliamSChips on Slashdot |
|
|
|
|
|
#12 |
|
Hobbyist Programmer
|
You can also pull true random numbers from random.org's via HTTP, SOAP, or CORBA, if you don't have a hardware random number generator. One of the things on my project list is to make the most useless hardware random number generator ever... using raindrops. No rain, no random bits for you! Luckily I live in Boston where it rains more or less constantly, so that shouldn't be a problem
![]() |
|
|
|
|
|
#13 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
It is for this approach that buffers/queues were invented. Unfortunately, the approach tends to fail when one needs it the most.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#14 | |
|
Professional Programmer
Join Date: Oct 2006
Posts: 257
Rep Power: 2
![]() |
Quote:
|
|
|
|
|
|
|
#15 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5
![]() |
Quote:
DaWei's point was that this distinction exists. In many cases, psuedo-random numbers appear sufficiently random to meet the needs of the task at hand, such as in many games, but the distinction is still there. The fact that they are deterministic can be an advantage (in that it allows identical data to be replicated in subsequent tests) or a disadvantage (where this quality can be exploited to predict numbers, which would be bad in, say, an electronic slot machine in a casino). @OP: Algorithms to generate psuedo-random numbers will use a seed value, and apply a series of operations on it to a) derive a new seed, and b) return a new pseudo-random number. Those that generate truly random numbers typically function by listening for some kind of noise. This noise might be actual sound-type noise, electromagnetic noise, radioactive decay, or whatever. The main requirement is that it fluctuates over time (the faster the better, generally, as it can thus be sampled at a greater speed). By measuring some aspect of said noise (such as amplitude or frequency), and comparing it to some threshold value, a binary one or zero result can be returned. By repeating this process, an arbitrarily long sequence of bits (and thereby bytes) can be assembled that is truly random. Such systems often apply some normalization to ensure there is a roughly uniform distribution; often this is done by adjusting the threshold value. For example, if the average amplitude of the signal over a given time period was x, the threshold could be set at 50% of x in the hopes that a value was equally likely to be either a one or zero. This normalization needs to be done carefully, however, to prevent bias from entering the system. After all, sometimes you really do get ten 'tails' results in a row when flipping a coin.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#16 |
|
Professional Programmer
Join Date: Oct 2006
Posts: 257
Rep Power: 2
![]() |
Thank you.. I appreciate it
. Another question (this is a question I found on my "possible midterm questions" study sheet and was unable to answer):"Write a single C statement that will print a random number from the set 2, 4, 6, 8, 10" If anyone can give a push in the right direction for that I would appreciate it. I couldn't find anything in my lecture notes for it (which isn't that surprising since the possible midterm questions have been compiled over the years & the lecture notes are kept fairly concise). |
|
|
|
|
|
#17 | |
|
Programmer
Join Date: Dec 2005
Posts: 67
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#18 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
For randomness good enough for encryption purposes,
consult information about /dev/random in the UNIX operating system. It is implemented in C |
|
|
|
|
|
#19 |
|
Professional Programmer
Join Date: Oct 2006
Posts: 257
Rep Power: 2
![]() |
Thanks - don't know why I didn't think of that
![]() but how would it be put into one line of code?
int array[5] = {2, 4, 6, 8, 10} ;
printf("%d", array[rand () % 5]); |
|
|
|
|
|
#20 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
printf ("%d", (rand () % 5 + 1) * 2);
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Median/Mode in arrays? {Need help} | Java|Tera | Java | 27 | Nov 29th, 2005 10:50 AM |
| FiveDigit + RandomeNumber Game. | TecBrain | Java | 0 | Nov 18th, 2005 2:53 PM |
| Random Number | coldDeath | Python | 1 | Sep 11th, 2005 8:17 AM |
| Random Number & Average Problem | Hadrurus | Java | 6 | Aug 15th, 2005 1:08 PM |
| non repeating random number generation | gencor45 | C# | 2 | Feb 9th, 2005 12:11 AM |