de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Displaying a random number
PostPosted: Sun Mar 24, 2013 3:47 pm 
Offline
Regular
Hello everyone,

Apologies to present another basic question, but have struggled a bit to get the line from the main documentation to work in my script:

getRandom(max)
Returns a random number between 0 and max (excluded).
Example : if(getRandom(2) == 0) ...

I'd like to use this to assign a number like "apply X number of clothespegs...". In that case does this information get "plugged" into the text in "show" or somewhere else?

Thanks for any direction you can provide!


Top
 Profile Send private message 
 
 Re: Displaying a random number
PostPosted: Sun Mar 24, 2013 5:32 pm 
Offline
Site Admin
User avatar
No need to apology, it's a pleasure.
getRandom() will create, return a number. Then the symbol + is enough to group some things in order to create a character string. Two examples :
Code:
def number = getRandom(6) + 1
def fullString = "Put "+number+" clothespegs"
show(fullString)

Shorter :
Code:
show("Put "+(getRandom(6) + 1)+" clothespegs")

As you can see, there's sometimes a trick : using parenthesis to make sure + concatenate strings or add numbers.


Top
 Profile Send private message 
 
 Re: Displaying a random number
PostPosted: Mon Mar 25, 2013 1:49 am 
Offline
Regular
Thanks for your help! Looking forward to publishing my first two scripts soon...


Top
 Profile Send private message 
 
 Re: Displaying a random number
PostPosted: Sat Apr 06, 2013 12:12 pm 
Offline
Shy
I've coded a quick shortcut here:

Code:
Random random = new Random()

def r = {
   min, max ->
   return random.nextInt((max+1)-min)+min
}

show("Put "+r(3,6)+" clothespegs on ya bits")

Gives you a random number between a minimum and a maximum. Useful for waiting random lengths of time, or giving yourself r(1,4)*6 strokes of the cane

LMW


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.