Random number

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

gnorm
Posts: 1
Joined: Fri Nov 05, 2021 11:52 am

Random number

Post by gnorm »

Hi,

i have to create a unique random number between 'min' and 'max' as a filename. My problem is a fast way for making sure that the generated number is already not used. Think i have to use a list (called in the not working example 'usedNums') to save the generated numbers and to test.

Can you help me? Sorry, for that, i'm an absolute newby ;)


function random() {
var num = return Math.floor(Math.random() * (max - min + 1)) + min;

while (usedNums.includes(num)) {
num = return Math.floor(Math.random() * (max - min + 1)) + min;
}

usedNums.Add(num);
return num;
}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Random number

Post by Kukurykus »

Code: Select all

objct = {}; while(objct.__count__ < nmbr = 10)
	v = ~~(Math.random() * nmbr) + 1, objct[v] = v;
(arr = objct.reflect.properties).splice(nmbr, 4), arr