- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Randomize string in C#
To randomize string, firstly use Random class −
Random r = new Random();
Now, use the Next() method with OrderBy() −
string random = new string(str.ToCharArray().OrderBy(s => (r.Next(2) % 2) == 0).ToArray());
Here is the compete code that displays randomize string −
Example
using System; using System.IO; using System.Linq; class Demo { static void Main() { const string str = "electronics"; Random r = new Random(); string random = new string(str.ToCharArray().OrderBy(s => (r.Next(2) % 2) == 0).ToArray()); Console.WriteLine("String = {0}", str); Console.WriteLine("Random String = {0}",random); Console.Read(); } }
Output
String = electronics Random String = lericsecton
- Related Articles
- Randomize color by number in JavaScript
- What is the use of randomize and srand functions in C language?
- Shuffle or Randomize a list in Java
- How to randomize an already created vector in R?
- How to randomize rows of a matrix in R?
- How to randomize (shuffle) a JavaScript array?
- How to randomize the items of a list in Python?
- How to randomize and shuffle array of numbers in Java?
- In MySQL, how can we randomize set of rows or values in the result set?
- How to randomize column values of a data.table object for all columns in R?
- Equals(String, String) Method in C#
- String Literal Vs String Object in C#
- How to randomize column values of a data.table object for a set of columns in R?
- Decode String in C++
- Prime String in C++

Advertisements