![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Templated Random Number Generator
Hi guys, new to the forum, plan to contribute here a lot as i get bored at work. Quick question on a Random Generator.
I'm making a library for common tasks in C++ ( random, XML Reader, HTML Document maker, etc ) and I am just wondering the best way to go about this is. Right now, even though it is templated, doubles and floats are never real numbers, always whole numbers. cpp Syntax (Toggle Plain Text)
I have been using this formula for 4 years during Java development, and works fine for whole number generation. I was just wondering what the best, and most efficent method of doing this would be. Last edited by Ben.Dougall; Jul 5th, 2007 at 7:39 PM. |
|
|
|
|
|
#2 | ||
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5
![]() |
Quote:
![]() Quote:
__________________
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 |
||
|
|
|
|
|
#3 |
|
Programmer
|
Thanks for the info, those articles are quite useful. I'll give it a try when I get some time.
Thanks again. |
|
|
|
|
|
#4 |
|
Programmer
|
cpp Syntax (Toggle Plain Text)
Thank you Lectric, the first link you gave me seems to have done the job. |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You understand that the return of rand, as usually implemeted in C/C++, is an integer, right? Casting doesn't give you a real number.
__________________
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 |
|
|
|
|
|
#6 | |
|
Programmer
|
Quote:
I have a feeling i can learn a lot from this forum. Thank again Dawei and lectric. |
|
|
|
|
![]() |
| 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 |
| [vb6] need advice concerning a largescale non-recurring random number generator | chepfaust | Visual Basic | 8 | Jun 8th, 2006 5:04 AM |
| 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 & 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 |