-
Notifications
You must be signed in to change notification settings - Fork 1.6k
F# Snippets for System.Random #7335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F# Snippets for System.Random #7335
Conversation
Docs Build status updates of commit 1acd577:
|
File | Status | Preview URL | Details |
---|---|---|---|
xml/System/Random.xml | View | Details | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/array1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/bytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/long1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextbytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextdoubleex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/same1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/unique.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/uniquearray1.fs | ✅Succeeded | View |
xml/System/Random.xml
- Line 0, Column 0: [Warning: invalid-code]
It looks like your code snippet was not rendered. Try range instead.
For more details, please refer to the build report.
If you see build warnings/errors with permission issues, it might be due to single sign-on (SSO) enabled on Microsoft's GitHub organizations. Please follow instructions here to re-authorize your GitHub account to Docs Build.
Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.
Note: Your PR may contain errors or warnings unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.
For any questions, please:
- Try searching the docs.microsoft.com contributor guides
- Post your question in the Docs support channel
Docs Build status updates of commit f95e3c8:
|
File | Status | Preview URL | Details |
---|---|---|---|
xml/System/Random.xml | View | Details | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor4.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/Next2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs | ✅Succeeded | ||
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next4.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/array1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/bytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/long1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextbytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextdoubleex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/same1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/unique.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/uniquearray1.fs | ✅Succeeded | View |
xml/System/Random.xml
- Line 0, Column 0: [Warning: invalid-code]
It looks like your code snippet was not rendered. Try range instead.
- Line 0, Column 0: [Warning: invalid-code]
The code snippet "~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.cs" could not be found.
For more details, please refer to the build report.
If you see build warnings/errors with permission issues, it might be due to single sign-on (SSO) enabled on Microsoft's GitHub organizations. Please follow instructions here to re-authorize your GitHub account to Docs Build.
Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.
Note: Your PR may contain errors or warnings unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.
For any questions, please:
- Try searching the docs.microsoft.com contributor guides
- Post your question in the Docs support channel
F# floats are 64bit and equivalent to doubles changed for consistency
Docs Build status updates of commit 1790a92:
|
File | Status | Preview URL | Details |
---|---|---|---|
xml/System/Random.xml | View | Details | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor4.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/Next2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs | ✅Succeeded | ||
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next4.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Sample/FS/sample.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/array1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/bytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/long1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextbytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextdoubleex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/same1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/unique.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/uniquearray1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.random.nextdouble/fs/nextdouble1.fs | ✅Succeeded | View |
xml/System/Random.xml
- Line 0, Column 0: [Warning: invalid-code]
The code snippet "~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.cs" could not be found.
- Line 0, Column 0: [Warning: invalid-code]
It looks like your code snippet was not rendered. Try range instead.
For more details, please refer to the build report.
If you see build warnings/errors with permission issues, it might be due to single sign-on (SSO) enabled on Microsoft's GitHub organizations. Please follow instructions here to re-authorize your GitHub account to Docs Build.
Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.
Note: Your PR may contain errors or warnings unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.
For any questions, please:
- Try searching the docs.microsoft.com contributor guides
- Post your question in the Docs support channel
Docs Build status updates of commit 05cd5d3:
|
File | Status | Preview URL | Details |
---|---|---|---|
xml/System/Random.xml | View | Details | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor4.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/Next2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next4.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Sample/FS/sample.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/array1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/bytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange3.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/long1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextbytes1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextdoubleex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/same1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex2.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/unique.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/uniquearray1.fs | ✅Succeeded | View | |
samples/snippets/fsharp/VS_Snippets_CLR_System/system.random.nextdouble/fs/nextdouble1.fs | ✅Succeeded | View |
xml/System/Random.xml
- Line 0, Column 0: [Warning: invalid-code]
It looks like your code snippet was not rendered. Try range instead.
For more details, please refer to the build report.
If you see build warnings/errors with permission issues, it might be due to single sign-on (SSO) enabled on Microsoft's GitHub organizations. Please follow instructions here to re-authorize your GitHub account to Docs Build.
Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.
Note: Your PR may contain errors or warnings unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.
For any questions, please:
- Try searching the docs.microsoft.com contributor guides
- Post your question in the Docs support channel
* fixed snippet number * fixed float printing to be more consistent with .ToString()
Docs Build status updates of commit 445780a: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
should be ready now |
Thanks @albert-du We've added a CI build for all our snippets. Can you include the .fsproj file for building these samples? Then, that step should pass, and this would be ready to merge. (I did a reasonable review, and once the build is clean, it's ready). |
Awesome, I'll add one when I get a chance |
Docs Build status updates of commit bc28888: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
@KathleenDollard - can you review? |
cc @baronfel as well, in case you are interested in reviewing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow what a set of changes! By and large they look correct, and idiomatic. I left a couple stylistic suggestions, and if you want you could go with using interpolated strings only, but I'm very happy with this overall. Thank you @albert-du!
Content notes about this type:
The following example uses the C# lock Statement and the Visual Basic SyncLock statement to ensure that a single random number generator is accessed by 11 threads in a thread-safe manner. Each thread generates 2 million random numbers, counts the number of random numbers generated and calculates their sum, and then updates the totals for all threads when it finishes executing.
It would be good to add a reference and link to the lock
function for F# here.
A lock (the lock statement in C# and the SyncLock statement in Visual Basic) protects access to the variables for the total count and sum of all random numbers generated on all threads.
It would be good to have a mention of the lock
function in F# here as well, though no link is necessary as with the other languages.
The NextBytes(Byte[], Byte, Byte) method wraps a call to the Next(Int32, Int32) method and specifies the minimum value and one greater than the maximum value (in this case, 0 and 101) that we want returned in the byte array. Because we are sure that the integer values returned by the Next method are within the range of the Byte data type, we can safely cast them (in C#) or convert them (in Visual Basic) from integers to bytes.
Similarly a brief statement about how we are safely casting using byte
in F#
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs
Outdated
Show resolved
Hide resolved
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs
Outdated
Show resolved
Hide resolved
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chet Husk <[email protected]>
Include information for F#
Docs Build status updates of commit 411d838: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
Docs Build status updates of commit f13fc9e: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
removed type annotations from array creation replaced another "double" with "float" normalized formatting
Docs Build status updates of commit 11f38b6: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Just a minor request to use string interpolation consistently throughout
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs
Outdated
Show resolved
Hide resolved
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs
Outdated
Show resolved
Hide resolved
Docs Build status updates of commit 5dcb992: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
ready! |
@BillWagner ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @albert-du
I'll now.
Add F# Code Snippets for System.Random
Describe your changes here.
Adds a few F# snippets for System.Random. Snippets are equivalent to C# and VB versions with a little refactoring to make them more idiomatic.