简体   繁体   English

重置“随机”数学

[英]reset 'random' math

I've got a random generator my using arrays and the following string to randomize: 我有一个使用数组和以下字符串进行随机化的随机生成器:

var doelgroepRand = doelgroepArray[Math.floor(Math.random() * doelgroepArray.length)];

/ /

var divergeerIdee = 'Laat een' + ' ' + doelgroepRand + ' ' + watRand + ' ' + handelingRand

This goes into 这进入

$('#something').click( function() { 
event.preventDefault();
alert(divergeerIdee); });
});

But to get a new set of random items, you need to refresh the page. 但是要获得一组新的随机项目,您需要刷新页面。 I want that, on click, everything is 'resetted' and you get new random items. 我希望单击时一切都“重置”,并且您会得到新的随机项目。

What is the string I need? 我需要什么字符串?

Simply pack it all in a javascript function. 只需将所有内容打包到javascript函数中即可。 Eg: 例如:

function createRandom() {
  var doelgroepRand = doelgroepArray[Math.floor(Math.random() * doelgroepArray.length)];
  return divergeerIdee = 'Laat een' + ' ' + doelgroepRand + ' ' + watRand + ' ' + handelingRand
}


$('#something').click( function() { 
    event.preventDefault();
    alert(createRandom()); 
    alert(createRandom()); 
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM