Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: joao9856 on June 15, 2013, 04:48:39 pm
-
is there any way to organize random numbers from the lowest to the biggest??
TI-Nspire CX calc
-
rand(100)->temp
SortA temp
should do what you want
-
can't seem to make it work could you explain it to me like i was a four year old??
-
rand(100)
gives a bunch of random numbers. It could be rand(42) or anything else
SortA temp
sorts temp. Now, temp is something like{0.011,0.0125,0.0151.....0.988}
-
i've searched and thats for lists, thinking is there any other way?
-
Well, is there any other way you had in mind? Using lists seems like the most straight-forward way. From this point, you can read list element 1, list element 2, list element 3, and so on.
-
^This. I'm not really sure what other way you would want to go about sorting numbers. From your post, I even assumed that you wanted a list.
-
the only problem is that i don't know how to place variables in a list.
I'm like this,
randint(1,50)->n
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
after this i'm as clueless as what to do as i can get
-
If it's the same than with z80 basic (TI-Basic for TI-82 to 84+), then you can access each element of a list this way :
temp(1)
temp(2)
temp(3)
...
-
I am not sure how it is done on the nSpire, but if it is similar enough to the 68K calcs, then you should be able to do something like this:
rand(50)→temp
SortA temp
And then to access a list element, you can do things like this:
temp[1] ;retrieve list element 1
n→temp[1] ; store n to list element 1
I hope this works and helps!
-
it say "error invalid data type"
-
At what line does it have an error?
-
at SortA temp line
-
what does
disp temp
display?
-
It displays whatever is stored in temp
-
it displays the contesnts of temp which is a array (i guess)
-
it displays the contesnts of temp which is a array (i guess)
It displays whatever is stored in temp
I was asking joao9856 what that displayed for him, I don't think it was clear enough. I am thinking that temp is not an array for some reason.
-
my code is
randint(1,11)->e
randint(1,11)->ee
randint(1,50)->temp
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
randint(1,50)->nnnnn
disp e
disp ee
disp temp
disp nn
disp nnn
disp nnnn
disp nnnnn
SortA temp
n->temp[1]
-
randint(1,50)
makes one random number from 1 to 50. SortA works on a list, which is several numbers in an order. lists are denoted by curly braces, {} and the elements, or members of the list, are separated by commas.
I think what you want is something like this:
randint(1,11)->e
randint(1,11)->ee
randint(1,50)->eee
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
randint(1,50)->nnnnn
{e,ee,temp,nn,nnn,nnnn,nnnnn}->temp ;put all of the varibles into a list
disp temp
SortA temp
disp temp
which could be optimized to
randint(1,50,7)->temp ;get 7 random numbers from 1 to 50 and store to temp
disp temp ;display the initial state of temp
SortA temp
disp temp ;display the end, sorted state of temp.
-
thanks now i can complete my program
-
you can sort the list.
For example,
local a
randseed 100
a = rand(5)
sortA a
disp a
-
my code is
randint(1,11)->e
randint(1,11)->ee
randint(1,50)->temp
randint(1,50)->nn
randint(1,50)->nnn
randint(1,50)->nnnn
randint(1,50)->nnnnn
disp e
disp ee
disp temp
disp nn
disp nnn
disp nnnn
disp nnnnn
SortA temp
n->temp[1]
no,no this use
It's not only rebundant but also complex and ugly.