1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Add random int utility function

This commit is contained in:
Bill Thornton 2023-03-14 01:32:36 -04:00
parent ff8b7427e3
commit 4937f2d60c
4 changed files with 17 additions and 17 deletions

View file

@ -18,6 +18,7 @@ import browser from '../../scripts/browser';
import { playbackManager } from '../playback/playbackmanager';
import itemShortcuts from '../shortcuts';
import imageHelper from '../../scripts/imagehelper';
import { randomInt } from '../../utils/number.ts';
import './card.scss';
import '../../elements/emby-button/paper-icon-button-light';
import '../guide/programs.scss';
@ -640,16 +641,6 @@ import { appRouter } from '../appRouter';
};
}
/**
* Generates a random integer in a given range.
* @param {number} min - Minimum of the range.
* @param {number} max - Maximum of the range.
* @returns {number} Randomly generated number.
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* Generates an index used to select the default color of a card based on a string.
* @param {?string} [str] - String to use for generating the index.
@ -669,7 +660,7 @@ import { appRouter } from '../appRouter';
return (index % numRandomColors) + 1;
} else {
return getRandomInt(1, numRandomColors);
return randomInt(1, numRandomColors);
}
}

View file

@ -1,3 +1,5 @@
import { randomInt } from '../../utils/number.ts';
let currentId = 0;
function addUniquePlaylistItemId(item) {
if (!item.PlaylistItemId) {
@ -56,7 +58,7 @@ class PlayQueueManager {
const currentPlaylistItem = this._playlist.splice(this.getCurrentPlaylistIndex(), 1)[0];
for (let i = this._playlist.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * i);
const j = randomInt(0, i - 1);
const temp = this._playlist[i];
this._playlist[i] = this._playlist[j];
this._playlist[j] = temp;