arrays - c++ rand() % 100 -
I am trying to fill an array with random 200 numbers which can be very much 0-100. I get this population that the last two numbers are very weird.
Here's my code.
for (int i = 0; i My output comes in this way
Original Array:
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61 91 95 42 27 36 91 4 2 53 92 82 21 16 18 95 47 26 71 38 69 12 67 99 35 94 3 11 22 33 73 64 41 11 53 68 47 44 62 57 37 59 23 41 29 78 16 35 90 42 88 6 40 42 64 48 46 5 90 29 70 50 6 1 93 48 29 23 84 54 56 40 66 76 31 8 44 39 26 23 37 38 18 82 29 41 33 15 39 58 4 30 77 6 73 86 21 45 24 72 70 29 77 73 97 12 86 90 61 36 55 67 55 74 31 52 50 50 41 24 66 30 7 91 7 37 57 87 53 83 45 9 58 21 88 22 46 6 30 13 68 91 62 55 10 59 24 37 48 83 95 41 2 50 91 36 74 20 96 21 48 99 68 84 81 34 53 99 18 38 88 88 67 28 93 48 83 7 21 10 17 13 14-858 993460 9 16 35 51 49 49 56 98 3 24 8 44 9 89 2 95 85 93 43 23 87 14 3 48 0 58 18 80 96 98 81 89 98 57 57 22 38 92 38 79 90 57 58 91 15 88 56 11 2 34 72 55 28 46 62 86 75 33 69 42 44 16 81 98 22 51 21 99 57 76 92 89 75 12 0 10 3 69 61 88 1 89 55 23 2 85 82 85 88 26 17 57 32 32 69 54 21 89 76 29 68 92 25 55 34 49 41 12 45 60 18 53 39 23 79 96 87 29 49 37 66 49 93 95 97 16 86 5 88 82 55 34 14 1 16 71 86 63 13 55 85 53 12 8 32 45 13 56 21 58 46 82 81 44 96 22 29 61 35 50 73 66 44 59 92 39 53 24 54 10 45 49 86 13 74 22 68 18 87 5 58 91 2 25 77 14 14 24 24 34 74 72 59 33 70 87 97 18 77-33686019 Note that the final number in each array is really weird, can I do something to avoid this? BTW These are two different arrays. Thanks everyone who posted! I'm working on it!
You are reading one beyond the end of the array. / P>
For example, if you pop an array with 200 elements, then you should write 0 to 199 to 0 or 200 to 1 or 200.
By the way - Rand () does not make the number 100 to 100%. This number will be created from 0 to 99.
Also, as Randy Howard says (thank you), you can get more random generation from the following on advice.
Comments
Post a Comment