c - My own random number generator -


I want to create a random number generator where the user specifies the range and quantity of the specified numbers. I want to make every number unique to it (no double). I made it so far (it generates but repeats some of them, why?)

  #include & lt; Time.h> # Include & lt; Stdio.h & gt; #include & lt; Windows.h & gt; # Include & lt; Conio.h & gt; Int main () {srand (time (faucet)); Int start, stop, zodiac; System ("chcp 1250> gt; nul"); Printf ("Welcome to Random Number Generators! \ N"); Printf ("\ n What border? \ Nfrom:"); Scanf ("% i", and Start); Printf ("to:"); Scanf ("% i", & amp; stop); Printf ("How many numbers?:"); Scanf ("% i", and Amount); Int number [zodiac]; For (int i = 0; i  number [0] = 5 numbers [1] = 6 numbers [ 2] = 2 numbers [3] = 8  

Now you are working on number [4] You generate 2 ... you are behind Scan the array and find that 2 is a hoax then you create a new number ... and generate 8 but you can make your j < / Code> Do not reset loop - you can only work backwards, and Ever see nothing that 8 is already in the array.

What do you do (for example [i] == number [ja]) {number [ii] = rand () start% ((+ 1 stop +) +); J = i; // Reset Loop}}

And note that your code can easily produce an infinite loop. Consider asking someone in numbers 1-3, and generate 4 of them. 1,2,3 ,? . This situation can never be satisfied, because you can not have 1-3 without repeating at least one.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -