Jump to content
  • add random word to Others class


    Sye24
    • Version: All Product: WRobot General Type: Suggestion Status: Not Added
     Share

    Hey @Droidz have you ever thought about adding a random word to the other class? so instead of GetRandomStringReadable or with GetRandomStringReadable to get a random word? Here a sample i made for myself, hope it can help you. i know its a little sloppy but it works.

     

    internal static class GetReadableString
        {
            public static String RandomWordGenerator(int NumberOfResults = 1)
            {
                var OnlineWord = WebRequest(URl + NumberOfResults);
                var CharList = new List<char> { '"', '[', ']' };
                if (NumberOfResults > 1)
                {
                    var ListofWords = CharRemoval(OnlineWord, CharList).Replace(",", "^");
                    List<String> WordList = new List<string>();
                    foreach (var _Words in ListofWords.Split('^'))
                    {
                        if (!WordList.Contains(_Words))
                            WordList.Add(_Words);
                    }
                    return WordList[_Random.Next(0, WordList.Count)];
                }
                return CharRemoval(OnlineWord, CharList);
            }
    
            private static String CharRemoval(String script, List<Char> ListofChat)
            {
                foreach (char C in ListofChat)
                {
                    script = script.Replace(C.ToString(), String.Empty);
                }
                return script;
            }
    
            private static String WebRequest(String UniformResourceLocators)
            {
                var httpRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(UniformResourceLocators);
                var httpResponse = (System.Net.HttpWebResponse)httpRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
            private static readonly Random _Random = new Random();
            private static readonly String URl = "https://random-word-api.herokuapp.com/word?number=";
        }

     


     Share


    User Feedback

    Recommended Comments



    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...