Fiddling around with random #s and odds. - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html) +--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html) +--- Thread: Fiddling around with random #s and odds. (/thread-9853.html) |
Fiddling around with random #s and odds. - Zack - 01-08-2007 I was fiddling around with chances, RND, and loops, and I noticed an abnormality...I think. Run this code: Code: dim as integer n Either a) I'm missing a very obvious progamming error, b) INT(RND*2000000)+1 is weighting certain numbers as more probable, c) I've made some sort of math error, which I doubt because the odds are fairly simple, or d) my computer is really slow at executing the loop. Which is it? Fiddling around with random #s and odds. - Moneo - 01-08-2007 You DIM'ed "n" as an integer. A positive integer only goes up to 32,767, assuming FB integers are 16 bits like in QB. Try the DIM as long. Regards..... Moneo Fiddling around with random #s and odds. - stylin - 01-08-2007 Try reading this: http://www.freebasic.net/wiki/wikka.php?wakka=CatPgStdDataTypes Fiddling around with random #s and odds. - Anonymous - 01-08-2007 Executes and quits within 1 second here. LONG and INTEGER are synonyms in FB, which is a 32-bit compiler Fiddling around with random #s and odds. - Zack - 01-08-2007 Quote:You DIM'ed "n" as an integer.INTEGERs are 32 bits in FB, as the others said. @cha0s: so what's going on? My computer won't generate 1234567, but yours will? Fiddling around with random #s and odds. - Dio - 01-09-2007 i ran the following code on my computer and unless i made a mistake (unfathomable, i know :roll: ) it won't generate 1234567 for me either. Code: dim as long n EDIT: strange, i changed the 1234567 to 123456 and then 2000000 to 200000 and it worked like a charm. :???: Fiddling around with random #s and odds. - Skyler - 01-09-2007 And this is useful how? Fiddling around with random #s and odds. - Moneo - 01-09-2007 Zack, I compiled and ran the following using QuickBasic 4.5, and it found 1234567 in about 3 seconds. Regards..... Moneo Code: dim n as long Fiddling around with random #s and odds. - Zack - 01-09-2007 Quote:i ran the following code on my computer and unless i made a mistake (unfathomable, i know :roll: ) it won't generate 1234567 for me either.That should make it quicker, because the chances of getting the number are now 10x better. Still should work the other way, though. Moneo: So it really is just my computer. Strange. Fiddling around with random #s and odds. - Skyler - 01-09-2007 That's what happens when you run Windows... igh: |