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
United-TI Archives -> TI-Basic
 
    » Goto page 1, 2, 3  Next
» View previous topic :: View next topic  
Author Message
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 14 Jun 2007 06:13:13 pm    Post subject:

I've done a bit of testing, and came up with the following expressions, using only [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rand, that are equivalent to the [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randBin(, [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randNorm(, and [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randInt(. By 'equivalent' I mean not only that they return values in the same range with similar probability, but that for the same seeds, they return the same value. Hopefully this is interesting to someone.

[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randInt(A,B

  • when A<B, [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]A+int((B-A+1)rand
  • when A>B, [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]B+int((A-B+1)rand
This one's pretty well known, although it might be less known that it returns the same values for the same seed. I know you could write the above as one statement with min( and abs(, but that would be harder to read.

[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randBin(N,P
    [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]sum(P>rand(N
The way this is written hides the reason randBin is so slow: it calls rand N times. For large N, you could probably make this function work much faster by calculating the probabilities of each outcome, and using a single call to rand to generate a number by those probabilities, but so far my efforts on this front are stumped, as the slowness of Basic seems to compensate. Or you could use the normal approximation, giving you [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(.5+randNorm(NP,√(NP(1-P. Obviously, this no longer has the same values as randBin for the same seed, though.

[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randNorm(X,S
    [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]X-SinvNorm(rand
This one's pretty intuitive, but the subtracting in there surprised me because it's the opposite of what I expected. It doesn't matter to the calculation, because the normal curve is symmetric. However, for the standard normal distribution, you have [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randNorm(0,1 corresponding to [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]-invNorm(rand when [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]invNorm(rand would have worked just as well. I guess it might make sense in the assembly code, though. But if you're using this function for standard normals, then using [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]invNorm(rand will be smaller than [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randNorm(0,1.
The equivalence also explains why and how putting in a negative standard deviation works. It doesn't make mathematical sense, but it works when you plug it into my formula.

[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randM(A,B→[A]
    [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]{A,B→dim([A]
    For(I,A,1,-1
    For(J,B,1,-1
    randInt(-9,9→[A](I,J
    End
    End
The obvious way to generate a random matrix. Although once again, TI is pretty silly about filling the elements in backwards (starting from the very last element and moving right to left and from the bottom to the top). Then again, the command itself is silly - not only does it not let you change the bounds, but it also fixes them on -9 to 9, of all things. Rolling Eyes

I suppose this would be pretty useful to someone who wanted to make randInt( and randBin( functions on the TI-89 series that would work exactly like the 83 series for the same seed.

Last edited by Guest on 19 Jan 2008 12:02:21 pm; edited 1 time in total
Back to top
Super Speler
Super Awesome Dude


Calc Guru


Joined: 28 Nov 2005
Posts: 1391

Posted: 14 Jun 2007 06:14:40 pm    Post subject:

How long did that take you o.O
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 14 Jun 2007 06:16:57 pm    Post subject:

Not that long - I was doing most of it while I was posting, actually. It would've taken a long time if I wanted to do it the "right way" and look at the assembly source, but I used the time tested method of "guess and check" instead.
Back to top
Super Speler
Super Awesome Dude


Calc Guru


Joined: 28 Nov 2005
Posts: 1391

Posted: 14 Jun 2007 06:30:50 pm    Post subject:

Hmm... topic pinned.
Back to top
Groene07


Member


Joined: 08 Jun 2007
Posts: 150

Posted: 14 Jun 2007 07:11:48 pm    Post subject:

Interesting... What does topic pinned mean?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 14 Jun 2007 07:38:33 pm    Post subject:

It means he pinned it so it always stays at the top of the topics list in the TI-Basic forum. Although honestly, I don't think this topic is that big of a deal.
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 14 Jun 2007 07:40:49 pm    Post subject:

[s]That means it is in the pinned section (i.e. it won't go out of view after x amount of months(i.e. it is on the top)).[/s] Beaten

The Randint( can be also written as int(low+rand(high-low+1


Last edited by Guest on 14 Jun 2007 07:41:35 pm; 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: 14 Jun 2007 07:43:18 pm    Post subject:

It can't, because rand(N has the additional meaning of generating a list of N random numbers, so you can't use it for multiplication.
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 14 Jun 2007 07:54:14 pm    Post subject:

[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(low+(high-low+1)rand

Better?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 14 Jun 2007 08:17:39 pm    Post subject:

Yep, this one works. It's just putting a number (that we know is an integer) inside int( rather than outside it.
Back to top
spandiv
-- Retired --


Active Member


Joined: 25 May 2003
Posts: 650

Posted: 14 Jun 2007 08:51:14 pm    Post subject:

DarkerLine wrote:
It means he pinned it so it always stays at the top of the topics list in the TI-Basic forum. Although honestly, I don't think this topic is that big of a deal.
Maybe you could add it to the routines list?
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 14 Jun 2007 08:52:55 pm    Post subject:

or pin it in the math section?
Back to top
Groene07


Member


Joined: 08 Jun 2007
Posts: 150

Posted: 14 Jun 2007 09:42:15 pm    Post subject:

I may sound utterly crazy, but how are these complicated random numbers. Isn't it just another routine to get a random number like rand or randint does??? Sorry if I'm wrong, but please enlighten me
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 14 Jun 2007 09:48:29 pm    Post subject:

Correct me if I'm wrong DarkerLine, but these are "complicated" random numbers because 'rand' is the actual random function, and randInt( and the others are algorithms manipulating the result of the base random function
edit:I was close, but DarkerLine had the better definition Sad


Last edited by Guest on 14 Jun 2007 09:49:58 pm; 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: 14 Jun 2007 09:48:31 pm    Post subject:

They're complicated compared to [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rand. [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rand is a very simple random number, with a uniform distribution from 0 to 1. [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randNorm( for example is a complicated random number, which can theoretically take on any value, but it's probably going to be in a specific interval.

(well, actually it can't go further than about 7.03 standard deviations away from the mean, due to floating point limitations. And even then the probability of that happening is one in a billion. But it could, theoretically)

Last edited by Guest on 14 Jun 2007 09:50:42 pm; edited 1 time in total
Back to top
Groene07


Member


Joined: 08 Jun 2007
Posts: 150

Posted: 14 Jun 2007 09:53:01 pm    Post subject:

Is there a need for such "complicated" random numbers? Will it harm anyone if I continue using randint? Cool
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 14 Jun 2007 09:55:09 pm    Post subject:

Well - TI decided to put those commands in, not me. I've only used randNorm( about once or twice in my whole life.

And of course, they serve completely different purposes: you can't substitute randNorm( for randInt( and expect your program to work. I can see a randNorm( command determining stats or damage in RPGs, but that's about it, and even there randInt( is good enough.
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 14 Jun 2007 09:55:33 pm    Post subject:

I think DarkerLine posted this because of all the "what is the rand thing?" "where do the random numbers come from" questions that are constantly asked, and it really is interesting where they come from, i never thought it would be that simple
Back to top
Groene07


Member


Joined: 08 Jun 2007
Posts: 150

Posted: 14 Jun 2007 10:03:17 pm    Post subject:

hmmm. I guess all I understand is psuedorandom (Kind of) what I got to thinking was There is no such thing as a random number PERIOD!!!! My basis is that lets say you were going to pick a number out of a hat....You are technically confined to the numbers in a hat and technically there was nothing random about that number because you deliberatly put your hand on to of THAT number. Same goes for if you spin a wheel of numbers its just not random. If someone knows of a true random number generator, or a way to come to a completly random number tell me, but I just don't think it's possible.

Yah!!! teh hundreth posterz!!!! Razz Very Happy Razz :biggrin: Razz Very Happy : Razz
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 14 Jun 2007 10:07:33 pm    Post subject:

If you want to find out a "true" random number, get the book "Meta Math" by Gregory Chaitain (I'm not sure about the first name, but I know that's the last name), the book goes fairly heavily into set theory
Or, the other "true" random number: of all numbers from 1-25, 23 is the most random (I can't remember where I heard this, but a group did a survey of people and the most common number was 23, people said it over 20% of the time)
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
    » Goto page 1, 2, 3  Next
» View previous topic :: View next topic  
Page 1 of 3 » All times are UTC - 5 Hours

 

Advertisement