AS Conversion - Random Number in Python?

Posted on
Sat Aug 08, 2020 9:34 am
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

AS Conversion - Random Number in Python?

Hoping to convert this script to Python.

Code: Select all
tell application "IndigoServer"
   set photoNumber to the value of variable "PhotosCount"
   set randomNumber to (random number from 1 to photoNumber)
   set the value of variable "Photos" to randomNumber as integer
end tell


Appreciate any help.

Thanks.

Carl

Posted on
Sat Aug 08, 2020 10:16 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: AS Conversion - Random Number in Python?

https://docs.python.org/2.7/library/random.html

so

Code: Select all
photoNumber = indigo.variables['PhotosCount']
randomNumber = int(random.random() * int(photoNumber.value))
indigo.variable.updateValue(photoNumber, value=unicode(randomNumber))


Untested. But it'll be close.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Aug 08, 2020 10:21 am
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: AS Conversion - Random Number in Python?

Couple small tweaks (importing module and adding 1 to randomNumber):

Code: Select all
import random
photoNumber = indigo.variables['PhotosCount']
randomNumber = int(random.random() * int(photoNumber.value)) + 1
indigo.variable.updateValue(photoNumber, value=unicode(randomNumber))

Image

Posted on
Sat Aug 08, 2020 10:14 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: AS Conversion - Random Number in Python?

Perfect...thanks!

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron