Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
vic9317


Newbie


Joined: 16 Nov 2008
Posts: 26

Posted: 29 Oct 2009 03:47:21 pm    Post subject:

So at my school, there's this (rather pointless) "game" that bored kids play during math class. It involves generating a random number between 1 and 1,000,000 via randInt(, and seeing who can get the lowest number before class ends.

That got me wondering, if I were to create a program to do this, how fast can the randInt( command execute? Would it be faster to generate a list of, say, 10 elements at a time, or would it be faster to just generate one number a time repeatedly, or does neither have any speed advantage? Obviously it depends on factors such as battery strength and free RAM, but I'm curious to see if different syntaxes have any sort of effect and by what margin.

Also, are there any faster ways to generate these numbers, i.e. is 1-Nint(Nrand faster/slower than randInt(1,N?

Furthermore, how does one go about testing the speed of certain commands? Is there a program (whether on the calculator or the computer) that does this in milliseconds, or do you just need a stopwatch and good reflexes?

Thanks.


Last edited by Guest on 05 Jul 2010 07:45:10 am; edited 1 time in total
Back to top
calcdude84se


Member


Joined: 09 Aug 2009
Posts: 207

Posted: 29 Oct 2009 04:01:20 pm    Post subject:

There might be an assembly program to do that. However, you can do it a lot more simply if you have a TI-84+(SE) by using the startTmr and checkTmr( commands.
I have never tested the comparative speeds of commands that do the same thing.
(Note: for your "game", the expression "1+int(E3min(rand(X" (supposed to be a small e) gives you the smallest number out of X trials)
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 29 Oct 2009 05:20:02 pm    Post subject:

L+1+int((U-L)rand(T is faster than randInt(L,U,T . (L=Lower, U=Upper, T=Number of Trials (Random Numbers) If T=1, omit the (or, before the T and the T.)

For info on/about command timings, I'd check:
http://tibasicdev.wikidot.com/timings


Last edited by Guest on 29 Oct 2009 05:20:34 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 29 Oct 2009 06:00:46 pm    Post subject:

ztrumpet wrote:
L+1+int((U-L)rand(T is faster than randInt(L,U,T .

126 seconds:

startTmr→X
For(L,1,10)
For(U,1,10)
For(T,1,10)
randInt(L,U,T
End
End
End
checkTmr(X

142 seconds:

startTmr→X
For(L,1,10)
For(U,1,10)
For(T,1,10)
L+1+int((U-L)rand(T
End
End
End
checkTmr(X

Other comparisons may be performed this way on a TI-84+.


Last edited by Guest on 05 Jul 2010 07:45:32 am; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 Oct 2009 11:51:48 pm    Post subject:

For an easy way to win this game, set 56654→rand before doing randInt().

Last edited by Guest on 05 Jul 2010 07:45:52 am; edited 1 time in total
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 30 Oct 2009 02:22:35 pm    Post subject:

Weregoose wrote:
ztrumpet wrote:
L+1+int((U-L)rand(T is faster than randInt(L,U,T .

126 seconds:

startTmr→X
For(L,1,10)
For(U,1,10)
For(T,1,10)
randInt(L,U,T
End
End
End
checkTmr(X

142 seconds:

startTmr→X
For(L,1,10)
For(U,1,10)
For(T,1,10)
L+1+int((U-L)rand(T
End
End
End
checkTmr(X

Other comparisons may be performed this way on a TI-84+.

lol, This is true.
If there wern't so many variables i.e. coded into a program, rand would be faster.

It's funny how I look dumb now. Very Happy


Last edited by Guest on 05 Jul 2010 07:46:22 am; edited 1 time in total
Back to top
vic9317


Newbie


Joined: 16 Nov 2008
Posts: 26

Posted: 30 Oct 2009 04:59:21 pm    Post subject:

Thanks everyone for the replies.

Weregoose wrote:
Other comparisons may be performed this way on a TI-84+.

How would one do this with a TI-83 Plus? (Just curious; I have a TI-84 Plus so the above is no problem.)

DarkerLine wrote:
For an easy way to win this game, set 56654→rand before doing randInt().

Ah, yes. I thought of seeding rand to get 1, but I had no idea what number the seed would be. How does someone calculate the number required for a certain output? Obviously it would be quite tedious to figure out manually, as a seed seems to affect other random commands given different arguments, i.e. randInt(1,E6) gives a different number than randInt(1,E7) though the seed is the same.

Once again, thank you to all.


Last edited by Guest on 05 Jul 2010 07:44:34 am; edited 1 time in total
Back to top
calcdude84se


Member


Joined: 09 Aug 2009
Posts: 207

Posted: 30 Oct 2009 05:06:41 pm    Post subject:

Comparisons of the type stated cannot be done on an TI-83+(SE) because it lacks a clock,
Given the calculator's random number generator algorithm, one could possibly find what seed is needed to get a certain output. I, however, have never looked into it, since I have no need.


Last edited by Guest on 30 Oct 2009 05:07:05 pm; edited 1 time in total
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 30 Oct 2009 09:44:32 pm    Post subject:

For more info on rand:
http://mpl.unitedti.org/?p=40
http://www.unitedti.org/index.php?showtopi...mp;#entry117017

On an 83, check how many times the run idicator scrolls.
Back to top
vic9317


Newbie


Joined: 16 Nov 2008
Posts: 26

Posted: 31 Oct 2009 07:16:29 pm    Post subject:

Brilliant! Thanks guys, I really appreciate it.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement