![]() |
|
[C] Need some help with while rand() function - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Need some help with while rand() function (/showthread.php?tid=6140353) |
Need some help with while rand() function - omy11 - Feb 16, 2021 So i am currently trying to create something where it randomly generates 13 letters depending on how many the user wants to generate. Ex: User inputs they want to generate 5 codes (13 letters each) program then generates 5 codes. I can't seem to figure out how to set a max number of generated codes and with a limit of 13 letters each. Whenever i run the program i just get this: https://gyazo.com/055750c49c3d3cff4fb0132a7de139e2 This is what i have so far for that, any help is appreciated! Code int amount_codes;RE: Need some help with while rand() function - SIM-4717218 - Feb 17, 2021 do you initialize the rand with srand(time(NULL)); ? RE: Need some help with while rand() function - HFDone - Feb 17, 2021 https://pastebin.com/WfrAbjKD RE: Need some help with while rand() function - SIM-574702 - Feb 17, 2021 You're not using amount_codes to limit loop. You have outer while loop that never ends. Also inner loop has "< 100" and you're generating N codes of 13 so where does 100 come from. I see you're trying to do it yourself so I'm not going to spoon feed you the code but if you're still stuck after these tips I can make you fixed version. RE: Need some help with while rand() function - omy11 - Feb 17, 2021 (Feb 17, 2021 09:59 AM)matemisic Wrote: You're not using amount_codes to limit loop. I'm going to take a look at again and see if i can figure it out now. Super new to c++ so some things i do does not make sense lol. Thank you! RE: Need some help with while rand() function - tux1 - Feb 17, 2021 I had a quick play around with this, if I understand your question correctly. The main issue with your code and why you were getting loads of random letters was because you did while(true) with no end so it just went on forever. Have a look at the below and read the comments, hope this helps Code /****************************************************************************** |