Currently I have two seperate dictionaries, one for racial ethnicity and one for country. Keys in both dicts are numbered 0 to length of dictionary whilst the Values are the actual races/countries themselves.
In a seperate class, I am utilising System.Random to select a number between 0 and the maximum length of the dictionary in order to call a random value from each one in order to be given a random race and random country upon start-up. However, I have now discovered that the race/country pairs are appearing the same every time.
In the code below, I am noticing that Caucasian is always paired with England and Asian is always paired with France. There are others but this is evidence that my randomiser just isn’t working as I’ve never seen Caucasian paired with anything other than England. I’m at a complete loss here, can anyone help me make these pairs ACTUALLY random?
Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
static class Lists
{
public static Dictionary<int, string> countries = new Dictionary<int, string>()
{
{ 0, "England" },
{ 1, "Italy"},
{ 2, "France" },
{ 3, "Spain" }
};
public static int countrieslength = countries.Count;
public static Dictionary<string, string> denonyms = new Dictionary<string, string>()
{
{"England", "English" },
{"Italy", "Italian" },
{"France", "French" },
{"Spain", "Spanish" }
};
public static Dictionary<int, string> races = new Dictionary<int, string>()
{
{0, "Caucasian" },
{1, "African-American" },
{2, "Hispanic" },
{3, "Asian" },
***
using System;
using System.Threading;
using UnityEngine;
public class Character : MonoBehaviour
{
public string Race;
public string Country;
public string CountryDenonym;
System.Random r_countries = new System.Random();
System.Random r_races = new System.Random();
void Start ()
{
Race = Lists.races[r_races.Next(0, Lists.raceslength)];
Country = Lists.countries[r_countries.Next(0,Lists.countrieslength)];
CountryDenonym = Lists.denonyms[Country];
}