Hi
There are some fixed no of text string
say :
public const string Str1 = "Text1";
public const string Str2 = "Text2";
.......
In the aspx page, there is a submit button. When user clicks it, a text message will be selected randomly to display as a label from those text string.
How should I write that random selection part of the C# code?
Thanks
How to select constant text string randomly from fixed no of strings?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Vimal KandasamyRank #2,151 · 661 reputationPosted Apr 9, 2009, 10:54 PM EDT
I have one idea
Store All your Strings in an array...
like
String[] ar={"hi","bye","a","b"};
then add below code in submit button
Random myrandom = new Random();
int index = myrandom.Next(0,ar.Length);
String ranStr=ar[index];
ranstr will contain random String...
try this...
jayanand kamble9 reputationPosted Apr 10, 2009, 12:47 AM EDT
it works...