Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Jiho Song
Jiho Song
16,469 Points

I'm so curious as to why this results in constant arrays of numbers,,?

int su=1, sum=0; for(;;){ sum+=(su*=10); printf("%d", sum); } return 0;

this is nowhere relevant to any topic in treehouse, however, i coincidently made this

source. This is from language plain c, it shows me only arrays of same number indefenitely.

whenever i multiply multiplies of 10 to variable 'su', it gives me same patteen of results.

i think this can be proven mathematically but dont know how. anyone can give me a hint?

ps. if i put number something else like 11 instead of 10, 210, 110, 1100, etc.., then it returns r

results with random arrays. So there must be some reasons

1 Answer

Steven Parker
Steven Parker
231,269 Points

I don't see any mystery here.

Nor do I see any "array". But I do see a sequence of numbers being produced by a perfectly predictable formula.

If by "arrays of same number" you mean that the numbers in the sequence all have a repeating digit, that's no surprise when the multiplier is 10 because you're just adding the same value moved over one decimal place each time.

And when the multiplier is something else, the values are not "random" but are also predictable even though they now contain other digits.

One final thing to consider is that the numeric representation of integer values has an upper limit which your sequence will quickly exhaust. So once the computed values exceed 10 digits in length the calculations will no longer be accurate. At that point, they may indeed appear to be "random". In fact, one common technique used for generating pseudo-random sequences involves deliberate numeric precision overflow.

Jiho Song
Jiho Song
16,469 Points

Big thanks for comment for this shabby idea.

the multiplier is 10 but when it exceeds somewhat over 10 digits, then it should appear somewhat random.

because it will be calculated as something like (upper value of int - 10^40)=(appears to be random)

and it will no more create the effect where the value moved over one decimal place each time.

so in this case also should have to be mixed sequence of "random" number.

Is there any thing i omitted to put in consideration? :(

Steven Parker
Steven Parker
231,269 Points

I would just point out again that "random" implies something more than "different". For example, if you put 1 instead of 10 as the multiplier, you will see different digits but it will obviously not be "random". The sequences produced by other multipliers are just as predictable from a mathematical point of view, they just require more effort for a human.