#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Help with random strins


    hi. im trying to have the nickname to be picked out
    randomly out of a word list but despite all my attemps none of them workd heres my code so far

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using FluorineFx;
    using FluorineFx.Messaging.Adapter;
    using FluorineFx.Messaging.Api.Service;
    using FluorineFx.Net;
    using System.Threading;
    using System.IO;
    
    namespace TinyChat_SPam
    {
        class Client : IPendingServiceCallback
        {
            private static Random rand = new Random();
            static string[] colors = { "#1965b6", "#32a5d9", "#7db257", "#a78901", "#9d5bb5", "#5c1a7a", "#c53332", "#821615", "#a08f23", "#487d21", "#c356a3" };
            static int colorIndex = 0;
    
            public NetConnection mNetConnection;
            private Thread thdHandler;
    
            public string roomName;
            public bool FlagDone = false;
    
            public const string MsgPath = "message.txt";
    
            public Client()
            {
            }
    
            public Client(string roomName)
            {
                mNetConnection = new NetConnection();
                mNetConnection.OnConnect += OnConnect;
                mNetConnection.OnDisconnect += OnDisconnect;
                this.roomName = roomName;
            }
    
            public void SetHandler(Thread thdHandler)
            {
                this.thdHandler = thdHandler;
            }
    
            private void OnConnect(object sender, EventArgs e)
            {
                if (mNetConnection.Connected)
                {
                    Console.WriteLine("Connected.");
                    Thread.Sleep(200);
                    SetNick("O" + GetRandomString(10) + "G");
    
                    Thread.Sleep(200);
                    foreach (string msg in File.ReadAllLines(MsgPath))
    {
                        SendMessage(new Message(msg));
                        Thread.Sleep(200);
    }
                }
                FlagDone = true;
            }
    
            private void OnDisconnect(object sender, EventArgs e)
            {
                Console.WriteLine("Disconnected.");
                thdHandler.Abort();
            }
    
            private void SetNick(string name)
            {
                mNetConnection.Call("nick", this, name);
            }
    
            private void SendMessage(Message message)
            {
                colorIndex++;
    
                if (colorIndex >= colors.Length)
                {
                    colorIndex = 0;
                }
                string tmp = message.Format(',');
                string[] param = new string[] { tmp, colors[colorIndex] + ",en" };
                mNetConnection.Call("privmsg", this, param);
            }
    
            private string GetRandomString(int length)
            {
                Thread.Sleep(25);
                rand = new Random(DateTime.Now.Millisecond / new Random().Next(2, 5));
                string tmpString = "";
                while (length-- > 0)
                {
                    tmpString += (char)rand.Next('a', 'z');
                }
    
                return tmpString;
            }
    
            public void ResultReceived(IPendingServiceCall call)
            {
                throw new NotImplementedException();
            }
        }
    }
    thx in advence
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    185
    Rep Power
    82
    hi. im trying to have the nickname to be picked out
    randomly out of a word list but despite all my attemps none of them workd heres my code so far
    I assume you're referring to the following method. I don't see where your "word list" comes into existence. You should provide a detailed description of how this method relates to your "word list". It appears that you are generating a random nickname but I just don't see how it relates to any "word list".

    Code:
     private string GetRandomString(int length)
            {
                Thread.Sleep(25);
                rand = new Random(DateTime.Now.Millisecond / new Random().Next(2, 5));
                string tmpString = "";
                while (length-- > 0)
                {
                    tmpString += (char)rand.Next('a', 'z');
                }
    
                return tmpString;
            }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0
    hi i finaly got it to work but im not sure if the way i do it is the best suited way to do it

    i use this

    Code:
                    var lines = File.ReadAllLines("nicknameslist.txt");
                    var r = new Random();
                    var randomLineNumber = r.Next(0, lines.Length - 1);
                    var line = lines[randomLineNumber];
    it reads trough a 17 mb list someone told me i should use a
    method with a bigger upper bound how do i do that

IMN logo majestic logo threadwatch logo seochat tools logo