Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Tscript - random in custom range?

Still a little green? Ask your beginner's questions here

Tscript - random in custom range?

Postby smbv » Tue Jun 12, 2018 10:13 pm

Hello, I wanted to create a random number, I used Tscript: rand($F) it was giving me a random number every frame, but I need to customize the range from 0-1 to "0.4 to 1.1", how can I do it just using a Tscript string?
smbv
 
Posts: 41
Joined: Thu Jun 22, 2017 7:11 pm

Re: Tscript - random in custom range?

Postby Achim » Wed Jun 13, 2018 2:20 am

fit(rand($F),0,1,.4,1.1)

Cologne area TD artists? Let’s get in touch

Achim
 
Posts: 1681
Joined: Wed Nov 14, 2007 1:52 pm
Location: Cologne

Re: Tscript - random in custom range?

Postby smbv » Wed Jun 13, 2018 10:00 pm

OMG thank you so much! :P
smbv
 
Posts: 41
Joined: Thu Jun 22, 2017 7:11 pm

Re: Tscript - random in custom range?

Postby nettoyeur » Fri Jun 15, 2018 6:53 pm

Nice one Achim!
And for future knowledge seekers, here's the Python variant:

Code: Select all
tdu.remap(tdu.rand(absTime.frame), 0, 1,  0.4, 1.1)


I was curious about performance, interestingly enough in TD build 2018.23470 the Python line gets optimized internally so much that it turns out to be faster than Tscript!
On my machine the Python version has 0.010 ms avg cooktime, while the Tscript version takes 0.016 ms.

See for yourself:
Attachments
random_remap_Tscript_vs_Python.tox
(702 Bytes) Downloaded 29 times
Idzard Kwadijk | freelance TouchDesigner consultant | LinkedIn
Checkout ChopChopChop.org - the TouchDesigner marketplace!
nettoyeur
 
Posts: 994
Joined: Mon Oct 15, 2012 12:00 pm
Location: Amsterdam, The Netherlands


Return to Beginners

Who is online

Users browsing this forum: Google [Bot] and 10 guests