Getting random item from Dictionary? Not random : <p>I am running multiple threads on my application and in each thread I need to get a random Dictionary item from the account. Now I know of course once in a while you'll get the same item from a small dictionary, but this dictionary has over a thousand items and I am still getting non-unique results?</p>

<p>What do I mean by that? I mean it'll give random results but usually they repeat</p>

<p>Examples:</p>

<pre><code>Picked the random username "aidan913"
Picked the random username "aidan913"
Picked the random username "abbiexox9"
Picked the random username "phelan193"
Picked the random username "pbeters92"
</code></pre>

<p>So It'll repeat it twice sometimes, but not actually give a fully unique item. Surely there has to be a way to get a unique item at least 9/10 times?</p>

<pre><code>public KeyValuePair&lt;int, BotInformation&gt; GetAccount()
{
    var account = new KeyValuePair&lt;int, BotInformation&gt;();

    var rand = new Random();
    var randomlyOrdered = _accounts.OrderBy(i =&gt; rand.Next());

    lock (locker)
    {
        foreach (KeyValuePair&lt;int, BotInformation&gt; entry in randomlyOrdered)
        {
            if (!entry.Value.Usable())
                continue;

            account = entry;
        }
    }

    if (!CoreUtilities.IsDefault(account)) // if it found one, update it?
    {
        using (var databaseConnection = Program.GetServer().GetDatabaseManager().GetConnection())
        {
            databaseConnection.SetQuery("UPDATE `accounts` SET `last_used` = '" + 
                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' WHERE `username` = '" + account.Key + "' LIMIT 1");
        }

        account.Value.LastUsed = DateTime.Now;
    }

    return account;
}
</code></pre>
