random numbers - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: random numbers (/showthread.php?tid=3197) |
random numbers - badger - 11-06-2024 Hello can someone tell me why this little program will not work i dont really understand why. badger thanks in advance Code: (Select All)
RE: random numbers - Dav - 11-06-2024 Hi there. There are a couple of reasons. You can't put a SUB in between main code like that. Move the SUB to the end of main code. AI chatbots often make this mistake when making QB64 code, even after telling it not to do it. Next thing, the SUB won't recognize the Dim variables you made in the main code unless they are DIM Shared, or if the are DIMmed inside the SUB instead. I moved the DIMs to inside the SUB below and it works, you could DIM them as shared in the main code instead if you need to use them in other SUB's. - Dav Code: (Select All)
RE: random numbers - badger - 11-06-2024 Hello thanks very much all that was a really big help. Have not used qb64 in a while. Badger RE: random numbers - Dav - 11-06-2024 You are very welcome. And welcome to the forum! I forgot to mention this - You will notice I didn't put the DECLARE SUB in the corrected code I posted, but it still works. In QB64PE you don't have to DECLARE SUB/FUNCTION before using them. - Dav. RE: random numbers - Kernelpanic - 11-07-2024 The entire program basically consists of just one procedur, which only makes sense for an AI. Without a procedur, and with a query about how many numbers should be drawn. Code: (Select All)
RE: random numbers - bplus - 11-07-2024 Could just put numbers into a deck and shuffle deck and pull the numbers out like dealing cards. Garantee no duplicates and no having to worry about them! RE: random numbers - bplus - 11-07-2024 Followup with code for most efficient shuffle known to mathematicians!: Code: (Select All) TopN = 52 RE: random numbers - bplus - 11-07-2024 Here is that code applied to your, @badger specific case: Code: (Select All) ' Generate a random number between -1 and 71 Ha! You have 14 sets of 5 unique and non intersecting sets of numbers from 1 Shuffle of deck of 73 cards. RE: random numbers - DANILIN - 11-08-2024 Binary Sequence Predictor "game"? (Read 10252 times) https://qb64forum.alephc.xyz/index.php?topic=4473.msg140722#msg140722 My favorite circle string "1 goto 1" 1 m = INT(RND*a)+1: IF ABS(d(i)-d(m)) < .1*a THEN v = v+1: GOTO 1 Controlled what all numbers is on new places plus minus diapazon from original place + Shuffling Letters https://qb64forum.alephc.xyz/index.php?topic=3982 Program above outputs repeats and the numbers -1 and 0 But even excluding -1 and 0, do we repetitions? There are Code: (Select All) For i = 1 To TopN ' results of shuffle So it's always worse than I have 0 repetitions |