not my best coding ever but....

BASIC Code wrote:
:°A
:" Str1
:For(X,1,8
:If 2fPart(iPart(A/(2^(X-1)))/2
:Then
:"1"+Str1Str1
:Else
:"0"+Str1Str1
:End
:End
:sub(Str1,1,8Str1
:Lbl 9
:"Input NEXT RAND? (Y/N),Str2
:"If Str2=Y
:1A
:"If Str2=N
:"0A
:"If Str2Y and Str2N
:"Goto 9
:If A
:Then
:sub(Str1,2,7)+sub(Str1,1,1Str1
:128("1"=sub(Str1,1,1))+64("1"=sub(Str1,2,1))+32("1"=sub(Str1,3,1))+16("1"=sub(Str1,4,1))+8("1"=sub(Str1,5,1))+4("1"=sub(Str1,6,1))+2("1"=sub(Str1,7,1))+("1"=sub(Str1,8,1
:3Ans+1X
:Disp X/767
:" Str1
:For(B,1,8
:If 2fPart(iPart(X/(2^(B-1)))/2
:Then
:"1"+Str1Str1
:Else
:"0"+Str1Str1
:End
:End
:sub(Str1,1,8Str1
:End
:If A
:
Generated by SourceCoder, © 2005 Cemetech
This line:

Code:
:Lbl 9
:"Input NEXT RAND? (Y/N),Str2
:"If Str2=Y
:1A
:"If Str2=N
:"0A
:"If Str2=/=Y and Str2=/=N
:"Goto 9

Can be optimized:

Code:

:0->A "Or Delvar A
:Repeat Ans=92 or Ans=71
:getkey
:End
:(Ans=92)->A

Also why did you have the quotation marks before the code on some lines?
whooppsss...forgot to remove some comments....
elfprince13 wrote:
whooppsss...forgot to remove some comments....

So those lines weren't supposed to be in the program?
something1990 wrote:
So those lines weren't supposed to be in the program?


correct
they used to be part of the program..then I decided they were too annoying and that ON would serve nicely to quit.
something1990 wrote:
This line:

Code:
:Lbl 9
:"Input NEXT RAND? (Y/N),Str2
:"If Str2=Y
:1A
:"If Str2=N
:"0A
:"If Str2=/=Y and Str2=/=N
:"Goto 9

Can be optimized:

Code:

:0->A "Or Delvar A
:Repeat Ans=92 or Ans=71
:getkey
:End
:(Ans=92)->A

Also why did you have the quotation marks before the code on some lines?
Don't worry about optimization. First make sure your algorithm works. Can you describe how your algorithm works?
it bit shifts a 1 byte string then multiplies by 3 and adds 1.
then I display the result divided by 767 (aka 11111111 * 00000011 + 00000001 + 00000001), to get it as decimal.
Wait, what? Where do these strings come from? Is this a pseudorandom number generator, or what?
jpez wrote:
Is this a pseudorandom number generator


EVERY random number generator is pseudorandom. Even a 'random number' you pick in your head will be pseudorandom, its impossible to get a truly random number
A pseudorandom number generator starts from a seed and uses a deterministic algorithm to generate the next number in the sequence. I couldn't tell whether his algorithm generates a sequence of numbers from a user-given seed or if it just alters a number given by the user in a "random" way.
jpez wrote:
A pseudorandom number generator starts from a seed and uses a deterministic algorithm to generate the next number in the sequence. I couldn't tell whether his algorithm generates a sequence of numbers from a user-given seed or if it just alters a number given by the user in a "random" way.


i knew what you meant, i was just pointing out the technicality that every 'random' number proggy is pseudorandom Wink
The only truly random number generator is something like taking the value of a pixel from a camera watching something like a lava lamp.
It starts out using startTmr (easily changed to allow seeding).

Then it converts between a Real variable and a binary string that only uses the low-order byte of the variable.
You have to explain these things in plain english. Just because we know TI-BASIC does not mean we instantly understand the context of your technical jargon.

@Kerm: I believe some random number generators use background static.
elfprince13 wrote:
It starts out using startTmr (easily changed to allow seeding).

Then it converts between a Real variable and a binary string that only uses the low-order byte of the variable.


That makes sense. So it seeds the generator with a timer value, turns it into a regular number, takes the bottom 8 bits of that number if it were represented in binary, and turns that into a string. Eh?

@Jpez: that would work too.
KermMartian wrote:
The only truly random number generator is something like taking the value of a pixel from a camera watching something like a lava lamp.


its still arguably not truly random. Better than most generators? yes. Truly random? not so much
It's an interesting proof-of-concept though to show a fairly good random number generator can be created in pure BASIC.
it uses essentially the same type of formula used by the TI-OS and the random functions in most programming languages. the formula may be more or less complicated, but the technique is the same.
Oh really? Interesting. Once I found some documentation on how the TI-OS rand( function works, but I don't remember where that was. :/
  
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
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement