title: Need help creating a random number generating button in google sheets
body: <p>I want to generate a random number between 1 and the value in cell &quot;a2&quot; on the same sheet using a button. Is this possible?</p>
  <pre><code>function onOpen() {
   var sheet = SpreadsheetApp.getActiveSpreadsheet(); 
    var entries = [ {name:&quot;Roll Dice&quot;,functionName:&quot;rollDice&quot;} ]; 
    sheet.addMenu(&quot;Script&quot;, entries); }; 
  
  function rollDice() {
   var ss = SpreadsheetApp.getActiveSpreadsheet(); 
   var sheet = ss.getSheetByName(&quot;Testing&quot;); 
   var cell = sheet.getRange(&quot;a4&quot;); 
   var range = sheet.getRange(&quot;a2&quot;); 
   cell.setValue(Math.floor((Math.random()*6)+1) ); };
  </code></pre>