Advertisement
sondrex76

Simple random Namegen

Aug 5th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Random_name_generator_BASIC
  12. {
  13.     public partial class RNGB : Form
  14.     {
  15.         public RNGB()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         Random R = new Random();
  20.         string RandomLetter = "abcdefghihjlmnopqrstuvwxyz";
  21.         string RandomVovel = "aeiou";
  22.         string RandomConsonant = "bcdfghjklmnpqrstvxyz";
  23.         int Vovel; // How many letters have been vovels after each other?
  24.         int Consonant; // Same as above but with consonants
  25.         bool First = true;
  26.  
  27.         bool IsVovel(char Info) // Adds +1 to vovel if it is a vovel, or +1 to con.. if it is a con..
  28.         {
  29.             for (int I = 5; I >= 0; I--)
  30.             {
  31.                 if (Info == RandomVovel[I])
  32.                 {
  33.                     return true;
  34.                 }
  35.             }
  36.             return false;
  37.         }
  38.  
  39.         char Letter() // Generate a raondom letter with some set logic
  40.         {
  41.             string LetterType = "";
  42.             char Letter = "A"[0];
  43.  
  44.             if (First == true && CbControl.Checked == true && TbLetter.TextLength == 1)
  45.             {
  46.                 try
  47.                 {
  48.                     Letter = TbLetter.Text[0];
  49.                 }
  50.                 catch (FormatException)
  51.                 {
  52.                     Letter = "A"[0];
  53.                 }
  54.             }
  55.             else
  56.             {
  57.                 if (First == true)
  58.                 {
  59.                     LetterType = RandomLetter;
  60.                 }
  61.                 else // code for making max two consonants or vovels appearing after each other.
  62.                 {
  63.                     int I = R.Next(1, 100);
  64.  
  65.                     if (Consonant == 2)
  66.                         LetterType = RandomVovel;
  67.                     else if (Vovel == 2)
  68.                         LetterType = RandomConsonant;
  69.                     else if (Vovel == 1)
  70.                     {
  71.                         if (I > 70) // Makes sure there are a 70% chance of there being only one vovel
  72.                             LetterType = RandomVovel;
  73.                         else
  74.                             LetterType = RandomConsonant;
  75.                     }
  76.                     else
  77.                     {
  78.                         if (I > 70) // Makes sure there are a 70% chance of there being only one consonant
  79.                             LetterType = RandomConsonant;
  80.                         else
  81.                             LetterType = RandomVovel;
  82.                     }
  83.                 }
  84.  
  85.                 Letter = LetterType[R.Next(0, LetterType.Length)]; // Set a letter to a random part of the string LetterType
  86.             }
  87.             bool V = IsVovel(Letter); // Checks if Letter is a 'vovel' or notvovel
  88.  
  89.             if (V)
  90.             {
  91.                 Vovel++;
  92.                 Consonant = 0;
  93.             }
  94.             else
  95.             {
  96.                 Consonant++;
  97.                 Vovel = 0;
  98.             }
  99.  
  100.             if (First)
  101.             {
  102.                 First = false;
  103.                 return char.ToUpper(Letter);
  104.             }
  105.             else
  106.                 return Letter;
  107.         }
  108.         private void BActivate_Click(object sender, EventArgs e)
  109.         {
  110.             string Text = "";
  111.             lblText.Text = "";
  112.             int lenght = 3;
  113.  
  114.             if (CbLenght.Checked)
  115.                 lenght = (int)NUDLenght.Value;
  116.  
  117.             for (int I = (int)NumUD.Value; I > 0; I-- )
  118.             {
  119.                 if (!CbLenght.Checked)
  120.                     lenght = R.Next(3, 8);
  121.  
  122.                 for (int Wordlenght = lenght;  Wordlenght > 0; Wordlenght--)
  123.                 {
  124.                     Text += Letter();
  125.                 }
  126.  
  127.                 lblText.Text += Text + "\n";
  128.                 Text = "";
  129.                 First = true;
  130.             }
  131.         }
  132.  
  133.         private void CbControl_CheckedChanged(object sender, EventArgs e)
  134.         {
  135.             if (CbControl.Checked)
  136.                 TbLetter.Visible = true;
  137.             else
  138.                 TbLetter.Visible = false;
  139.         }
  140.  
  141.         private void CbLenght_CheckedChanged(object sender, EventArgs e)
  142.         {
  143.             if (CbLenght.Checked)
  144.                 NUDLenght.Visible = true;
  145.             else
  146.                 NUDLenght.Visible = false;
  147.         }
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement