❔ How can you create a string that creates random characters?
Title ^
(Console application)
10 Replies
The most reasonable way would probably be to use a
StringBuilder
You could append a random character to the builder, and repeat that for as many characters you wantIs there any documentation
Or something I can read about it
❯ Class: System.Text.StringBuilder
Represents a mutable string of characters. This class cannot be inherited.
❯ Struct: System.Text.StringBuilder.ChunkEnumerator
Supports simple iteration over the chunks of a StringBuilder instance.
❯ Struct: System.Text.StringBuilder.AppendInterpolatedStringHandler
Provides a handler used by the language compiler to append interpolated strings into StringBuilder instances.
3/25 results shown ~ Click Here for more results
React with ❌ to remove this embed.
You'll also want to look into the
Random
class❯ Class: System.Random
Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.
❯ Class: System.IO.RandomAccess
Provides offset-based APIs for reading and writing files in a thread-safe manner.
❯ Class: System.Security.Cryptography.RandomNumberGenerator
Provides functionality for generating random values.
3/25 results shown ~ Click Here for more results
React with ❌ to remove this embed.
Okay
You can use faker package https://github.com/bchavez/Bogus to generate fake data, very useful with Unit tests. but maybe to much for your simple need
GitHub
GitHub - bchavez/Bogus: A simple fake data generator for C#, F#, an...
:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js. - GitHub - bchavez/Bogus: A simple fake data generator for C#, F#, and VB.NET. Based o...
Is there any tutorials on this like videos?
I'd implement it yourself as a learning exercise
here's some pseudocode
- create an array of possible characters
- create an empty string to target
- instantiate a new instance of Random()
- while the length of the target string is less than desired,
--- create an index int using Random.Next() and the length of the array
--- add the character at the index to the target string
- when length is satisfied, return the string
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.