title: How to call a random value from an array in a dictionary? (Discord Bot)
body: <p>I have a dictionary, let's say:</p>
  
  <pre><code>var array1 = ["value 1", "value 2", "value 3"];
  var array2 = ["value 1", "value 2", "value 3"];
  
  var dict = {"this":array1,"that":array2};
  </code></pre>
  
  <p>How do I call a random value within the array from the dictionary given that I have chosen a key?</p>
  
  <p>e.g.</p>
  
  <pre><code>dict["this"] // Should return a random value from array rather than all values
  </code></pre>
  
  <p>I have tried using Math.random to get a random index number, which kind of works, but when using it, it always return the same value, which implies that the random number generator used for the index only runs once and does not update, resulting in giving the same value from the array every time unless I restart the code.</p>
  
  <pre><code>var array1 = ["value 1", "value 2", "value 3"]; // array1
  var array2 = ["value 1", "value 2", "value 3"]; // array2
  
  var randthis = Math.floor(array1.length * Math.random()); // random index for array 1
  var randthat = Math.floor(array2.length * Math.random()); // random index for array 2
  
  var dict = {"this":this[randthis],"that":that[randthat]};
  
  msg.client.send(dict[this])
  </code></pre>
  
  <p>How should I make it so the random index will give me a different one every time? Or a different way to achieve this.
  I know that I can achieve this in Python by importing random and using random.choice(dict[this])</p>
  
  <p>Update:
  I have the dictionary in a different module from my server module to not have too much code in the same module. So I am exporting the dictionary from dictionary.js and using it in actualcode.js (Don't think this matters, but going to state it just to make sure)</p>
  
  <p>Update 2:</p>
  
  <p>server.js:</p>
  
  <pre><code>const Discord = require("discord.js");
  const client = new Discord.Client;
  const cmd = require("./commands");
  
  client.on("message", msg =&gt; {
    const prefix = '$'
  
    if (msg.author == client.user){
      return
    };
  
    if (msg.content.startsWith(prefix)){
      var command = msg.content.split(prefix).slice(1);
      msg.channel.send(cmd[command+"_cmd"]);
    }
  
  });
  </code></pre>
  
  <p>commands.js:</p>
  
  <pre><code>var array1 = ["value 1", "value 2", "value 3"]
  var array2 = ["value 1", "value 2", "value 3"]
  var randindex = Math.floor(array1.length * Math.random())
  var randindex2 = Math.floor(array2.length * Math.random())
  
  var cmd = {"test_cmd":array1[randindex], "test2_cmd":array2[randindex2]}
  
  module.exports = cmd
  </code></pre>