mike55 Posted February 11, 2005 Posted February 11, 2005 Hi all Am trying to write a simple poker game using vb.net, have option strict on, am trying to generate a random number between 1 and 13 using the following line of code number = CInt(Int((13 * Rnd()) + 1)) However the line just seems to generate the value "1" all the time and so my code goes into an infiniate loop. Would appreciate it if someone could point out what is wrong with this line of code. Mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
mike55 Posted February 11, 2005 Author Posted February 11, 2005 Problem solved, not to worry. Mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted February 11, 2005 Administrators Posted February 11, 2005 You should really look at the System.Random class - far more useful. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mskeel Posted February 14, 2005 Posted February 14, 2005 And if you are looking for truly random numbers.... http://www.randomnumbers.info/ as created by a quantum computer at the Universtiy of Geneva. Think about all the parallell universes you create with just the single click of a button... Probably not applicable here, as you have a few more restrictions for a poker game, but it's pretty cool and along the same thread. Plus, I bet you don't want to have to make your app web-enabled. But you could just download blocks of random numbers. (overikill in every sense a deterministic number generator will work great) Quote
*Gurus* Derek Stone Posted February 14, 2005 *Gurus* Posted February 14, 2005 [msdn]System.Security.Cryptography.RNGCryptoServiceProvider[/msdn] Quote Posting Guidelines
thenerd Posted February 14, 2005 Posted February 14, 2005 It's usually not that hard to make your own random function, I did it in Qbasic when I was bored at school. Use the current time as a seed, possibly have a variable that counts how many times the function was used too and add that do the seed, then, to make sure the numbers aren't too close together do all types of crazy math like: if seed mod 2 = 0 then seed = seed -832478 and all types of stuff like that. You'll get some crazy cool random numbers. OR! look into the random class and save yourself some time (Though making your own IS pretty fun) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.