Skip to content

Commit 1e77d31

Browse files
committed
feat(csharp): improve randomness in temporary index name generation using byte array from RandomNumberGenerator
1 parent 8305799 commit 1e77d31

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,11 @@ public async Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(
933933
scopes = new List<ScopeType> { ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms };
934934
}
935935

936-
var randomSuffix = 100_000 + RandomNumberGenerator.GetInt32(900_000);
936+
var rng = RandomNumberGenerator.Create();
937+
var bytes = new byte[4];
938+
rng.GetBytes(bytes);
939+
940+
var randomSuffix = (Math.Abs(BitConverter.ToInt32(bytes, 0)) % 900001) + 100000;
937941
var tmpIndexName = $"{indexName}_tmp_{randomSuffix}";
938942

939943
try
@@ -1426,7 +1430,11 @@ public async Task<ReplaceAllObjectsWithTransformationResponse> ReplaceAllObjects
14261430
scopes = new List<ScopeType> { ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms };
14271431
}
14281432

1429-
var randomSuffix = 100_000 + RandomNumberGenerator.GetInt32(900_000);
1433+
var rng = RandomNumberGenerator.Create();
1434+
var bytes = new byte[4];
1435+
rng.GetBytes(bytes);
1436+
1437+
var randomSuffix = (Math.Abs(BitConverter.ToInt32(bytes, 0)) % 900001) + 100000;
14301438
var tmpIndexName = $"{indexName}_tmp_{randomSuffix}";
14311439

14321440
try

0 commit comments

Comments
 (0)