![]() |
generating a random number in the full range of that number? (Integer, Long) - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: generating a random number in the full range of that number? (Integer, Long) (/showthread.php?tid=3658) |
generating a random number in the full range of that number? (Integer, Long) - madscijr - 05-01-2025 I'm trying to generate random numbers in the full range of a value, for example an integer can be -32,768 to 32,767 and a long can be -2,147,483,648 to 2,147,483,647. If I try those for the min, max values, it always returns the max negative value - even if I try changing the type of NumSpread to a bigger type... I tried upto _Integer64 and it still doesn't work. Any idea how to get it to return a random value in the full range? Any help appreciated... Code: (Select All) ' Type Name Type suffix symbol Minimum value Maximum value Size in Bytes RE: generating a random number in the full range of that number? (Integer, Long) - SMcNeill - 05-01-2025 For integer... DIM NUM AS INTEGER Num = INT(RND * 65536) That's it. Long would be the same, but with the bigger value of an Unsigned Long RE: generating a random number in the full range of that number? (Integer, Long) - madscijr - 05-01-2025 Thanks - it's amazing how simple that is. One thing that tripped me up was the INT function... I thought that was only for integer types, so I'd need to find the Long equivalent, so I tried CLNG, but no workie. I tried INT and it worked. Code: (Select All) Do |