[英]Getting a random number in JS
我對JS有點陌生。 我有在特定游戲中不斷下注的代碼,並且我試圖使其跳過設置的數組中的隨機會話數。
現在,由於某種原因,它完全跳過了4個會話。 我究竟做錯了什么?
我也很想知道如何在控制台中顯示選擇的號碼。
/** -------------- Settings -------------- **/
var array = [0,1,2,3,4,5];
var num = Math.floor(Math.random() * array.length);
var roll = array.splice(num, 1);
var yourNumber = roll[ 0 ];
var settings = {
'baseBet': 1,
//Your base bet
'nyanMultiplier': 1.10,
//What multiplier would you like to grab
'waitGames': yourNumber,
//How many games should we wait before starting the bet
};
/** -------------- Settings -------------- **/
var script = {
'totalWaited': 0,
'placingBet': false,
'attempts': 0
};
engine.on('game_starting', function(info)
{
if(script.totalWaited >= settings.waitGames)
{
script.placingBet = true;
engine.placeBet(Math.round(settings.baseBet) * 100, Math.round(settings.nyanMultiplier * 100), false);
log('Placing bet now');
}
else
{
log('Still waiting before we place the bet.');
script.placingBet = false;
}
if(script.placingBet)
{
if (engine.lastGamePlay() == 'LOST')
{
log('Shot and a miss, maybe next game <3');
}
else
{
log('YO WE GOT IT. GG <3');
script.totalWaited = 0;
script.attempts = 0;
settings.waitGames;
}
}
});
engine.on('game_started', function(data)
{
if(!script.placingBet)
{
script.totalWaited++;
}
else
{
script.attempts++;
}
});
function log(message)
{
console.log('[Bot] ' + message);
}
您的數組長度為6,因此: Math.floor(Math.random() * array.length);
將在0-5之間創建一個數字。
該“拼接”不僅會從數組中檢索單元格的數量(在您的情況下為1),還會對原始數組進行突變並刪除這些單元格。
除非有意,否則請使用slice 。
yourNumber
可以為4,但您的代碼正確,因此它實際上應該是該數組中的隨機數。 從這里移至第二個請求console.log(yourNumber)
是將其打印到可用控制台的方式(如我所見,已在log
函數中實現)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.