Created
August 7, 2019 17:31
-
-
Save lukepuplett/728929569be94b0d7525e14418550d85 to your computer and use it in GitHub Desktop.
How to round robin writing to an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int length = 10; | |
var numbers = new int[length]; | |
int r = 0; | |
for (int i = 0; i < 100000; i++) | |
{ | |
r = unchecked(r + 1); | |
numbers[r % length] = r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think .NET integers are unchecked by default so this might work, too.