class Program
{
    static void Main(string[] args)
    {
        //array of strings
        string[] phrases = { "Buy it today", "You won't regret your purchase", "Satisfaction is guaranteed", "Purchase of a lifetime", "Such a great deal", "Limited time only" };
        Random r = new Random();
        string random = phrases[r.Next(0, 5)];
        string random2 = phrases[r.Next(0, 5)];
        string random3 = phrases[r.Next(0, 5)];
        RanStrings(random, random2, random3);
    }
    private static void RanStrings(string random, string random2, string random3)
    {
        Console.WriteLine(random);
        Console.WriteLine(random2);
        Console.WriteLine(random3);
    }
}
            Asked
            
        
        
            Active
            
        
            Viewed 51 times
        
    -2
            
            
        - 
                    Please tag your question with the language (Java?). And you need to explain your question, not just post a bunch of code. – Barmar Sep 18 '14 at 18:16
- 
                    [Shuffle](http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp) and `Take(3)`? – crashmstr Sep 18 '14 at 18:44
2 Answers
0
            
            
        your question is not very clear, but according to my understanding, you need a method to check equlity like:
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
namespace FormLetter
{
    class Program
    {
        static void Main(string[] args)
        {
            string random="";
            string random2 ="";
            string random3 ="";
         do{
            //array of strings
            string[] phrases = { "Buy it today", "You won't regret your purchase", "Satisfaction is                   guaranteed", "Purchase of a lifetime", "Such a great deal", "Limited time only" };
            Random r = new Random();
            random = phrases[r.Next(0, 5)];
            random2 = phrases[r.Next(0, 5)];
            random3 = phrases[r.Next(0, 5)];
           }while(compareStrings(random,random2, random3))
            RanStrings(random, random2, random3);
        }
        private static void RanStrings(string random, string random2, string random3)
        {
            Console.WriteLine(random);
            Console.WriteLine(random2);
            Console.WriteLine(random3);
        }
        private static bool compareStrings(string random, string random2, string random3)
        {
            //put here your comparison code
            if (there is equality between 2 strings passed in argument)
            return true;
            else  return false;
        }
    }
}
 
    
    
        Amazigh.Ca
        
- 2,753
- 2
- 11
- 8
0
            
            
        It sounds like you want to "shuffle" the strings rather than picking one at random (essentially random selection without replacement).  If that's the case just use an OrderBy with a random number:
Random r = new Random();
string[] phrases = { "Buy it today", "You won't regret your purchase", "Satisfaction is guaranteed", "Purchase of a lifetime", "Such a great deal", "Limited time only" };
phrases = phrases.OrderBy(s => r.Next()).ToArray();
// now just take the "first" 3    
RanStrings(phrases[0], phrases[1], phrases[2]);
 
    
    
        D Stanley
        
- 149,601
- 11
- 178
- 240
 
    