Like Tree4Likes
  • 3 Post By Matticus
  • 1 Post By Salem

picking out a random word as a nickanme

This is a discussion on picking out a random word as a nickanme within the C++ Programming forums, part of the General Programming Boards category; hi i got this code here id like for it to pick up a random word from a text file ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    5

    picking out a random word as a nickanme

    hi i got this code here id like for it to pick up a random word from a text file and use it as the nick in this line

    Code:
           SetNick(GetRandomString(10));

    how could i do it heres the full code for the client

    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();
            }
        }
    }

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,173
    This looks like C#, not C++.
    I think it would be better off in the C# section.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,068
    In other words: You found this code from somewhere else, and are asking all over the internet for someone to change it for you.
    Elysia, Elkvis and Salem like this.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    Not to mention right here as well!
    question about how to chose a random word

    Closed.
    Matticus likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Picking random numbers from an array
    By toyganozy in forum C Programming
    Replies: 2
    Last Post: 04-06-2012, 07:52 PM
  2. Random Word Generator? Plz Help
    By jjwballer in forum C Programming
    Replies: 7
    Last Post: 12-09-2010, 03:09 PM
  3. randomly picking a word out of a text file
    By lilrayray in forum C Programming
    Replies: 11
    Last Post: 08-01-2006, 06:26 PM
  4. Picking out random words
    By beanroaster in forum C++ Programming
    Replies: 16
    Last Post: 09-04-2005, 04:02 AM
  5. Random selection of a word
    By doobyscoo in forum C Programming
    Replies: 1
    Last Post: 04-14-2003, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21