-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FS-1135 implementation - random functions for collections (#17277)
* Random functions: old version rebased * Random functions: Rename functions according to the RFC * Random functions: More naming refactoring and documentation * Random functions: More documentation coments * Random functions: Added randomShuffleInPlace functions and docs * Random functions: refactoring * Added null checks * Added *by functions * Random functions: Array random functions tests * Added tests for lists and seqs * Random functions: addded *By tests to arrays and sequences * Random functions: addded *By tests to lists * Random functions: try fix CI * Random functions: review fixes * Try fix CI * Changed thread local implementation to thread static for performance per review * PR review fix * PR fix * PR review fix * Reverted HashSet constructor improvement since not netstandard2.0 compatible * Fix formatting * Fixed nan case for randomizer function * PR review fixes * PR review changes * Fixed input length check logic for sample --------- Co-authored-by: Petr <psfinaki@users.noreply.github.com>
- Loading branch information
Showing
17 changed files
with
2,660 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.FSharp.Core | ||
|
||
open System | ||
open System.Runtime.CompilerServices | ||
open System.Threading | ||
|
||
[<AbstractClass; Sealed>] | ||
type internal ThreadSafeRandom() = | ||
|
||
[<DefaultValue>] | ||
[<ThreadStatic>] | ||
static val mutable private random: Random | ||
|
||
[<MethodImpl(MethodImplOptions.NoInlining)>] | ||
static member private Create() = | ||
ThreadSafeRandom.random <- Random() | ||
ThreadSafeRandom.random | ||
|
||
// Don't pass the returned Random object between threads | ||
static member Shared = | ||
match ThreadSafeRandom.random with | ||
| null -> ThreadSafeRandom.Create() | ||
| random -> random |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Microsoft.FSharp.Core | ||
|
||
open System | ||
|
||
[<AbstractClass; Sealed>] | ||
type internal ThreadSafeRandom = | ||
static member Shared: Random |
This file contains 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
Oops, something went wrong.