Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Large Random Numbers in C++
Name: zpeterz63 Date: January 14, 2005 at 12:18:41 Pacific OS: Mandrake 10.1/XP dual boo CPU/Ram: 2.4 Celeron/512
Comment:
I'm looking for a way to large random numbers beyond the limit of rand(). I have an idea on how I can do this but was wondering if C++ by chance had anything to help me out built in or if someone how found a convenient way to do this.
Name: BlueRaja Date: January 14, 2005 at 16:17:44 Pacific
Reply:
Well the easy thing to do would be to add two rand()'s and modulus them.. The best and most practical thing to do would be to write your own png, or find one meant for larger numbers on the internet; google it.
BlueRaja.admin@gmail.com
0
Response Number 2
Name: Wolfbone Date: January 14, 2005 at 16:26:40 Pacific
Reply:
Use the GMP library. I don't know if it's ported/portable to Windows or not but it's the best there is (pari/gp uses it). The Mandrake distro already has it but here's the website anyway:
http://www.swox.com/gmp/
Getting random numbers out of GMP isn't too difficult but I found the documentation can be quite confusing so here's a natural number example which uses the high quality entropy pool in /dev/random and is the only use I've ever made of GMP's random number facilities anyway :)
0
Response Number 3
Name: Wolfbone Date: January 14, 2005 at 17:12:08 Pacific
Reply:
Sorry about the awful code - it's from among my earliest attempts in C. I've just removed a couple of obvious stupidities but there are probably others.
Summary: You would need to use the modulus operator for random numbers in C++. So you would do something like: rand() % 30; That would give you a random number from 0 to 30. Hope this helps. - Rolos ...
Summary: Hi I have a little bit of difficulty generating random numbers in assembly. However, the problem here is that, I want to generate random numbers in the range of 65d to 90d (from A to Z). But I don't k...