machine independent matching sets of Pseudo Random numbers
tripjack
Posts: 13
Hi everyone,
I'm looking for a way to generate,·store, and retrieve·values in·an 8 x 8 table of pseudo random integers
with each·value in the range of 0-9999, such that any time I use the same two seeds I can
get the same result, no matter which computer I run the algorithm on.
The subroutine should accept one WORD size seed (0-65535) and one BYTE size seed (0-7)
The subroutine should return a two dimensional matrix 8 cols by 8 rows
Once the table was·generated I would like to:
1. Store the table in memory on a stamp BS2sx
2.·Read the contents of each value in the table by referencing the row/col index
3. run the algorithm on another PC and generate the same table
I'm not trying to develop a high security application, just looking for a simple way to pair a·matrix of semi-random data in a stamp with an externally generated·matrix from another computer using an arithmetic·algorithm that will·produce the same results·on any machine.
I'm a pbasic newbie, so any examples of how to read and write arrays into memory would be very helpful.
Thanks for your advice and consideration.
Respectfully,
David
I'm looking for a way to generate,·store, and retrieve·values in·an 8 x 8 table of pseudo random integers
with each·value in the range of 0-9999, such that any time I use the same two seeds I can
get the same result, no matter which computer I run the algorithm on.
The subroutine should accept one WORD size seed (0-65535) and one BYTE size seed (0-7)
The subroutine should return a two dimensional matrix 8 cols by 8 rows
Once the table was·generated I would like to:
1. Store the table in memory on a stamp BS2sx
2.·Read the contents of each value in the table by referencing the row/col index
3. run the algorithm on another PC and generate the same table
I'm not trying to develop a high security application, just looking for a simple way to pair a·matrix of semi-random data in a stamp with an externally generated·matrix from another computer using an arithmetic·algorithm that will·produce the same results·on any machine.
I'm a pbasic newbie, so any examples of how to read and write arrays into memory would be very helpful.
Thanks for your advice and consideration.
Respectfully,
David
Comments
Attached is a java class for the javelin, that generates 'random' numbers using
16bit integer math. You can open the file with notepad.
You can implement the random function in PBASIC for the basic stamp,
and for example in C for a pc application.
regards peter
As I understand it, you are suggesting that I should use java in order to get machine independent code, is that correct?
If that is so, then my first question is, will· the javelin VM return the same number everytime from the
·random(nSeed) function if the nSeed is the same, regardless of the machine platform?
For ex: I have an embedded device and using javelin I run the random(nseed) function with nSeed of '81' and the function returns, let's say: '12345'
If I ran the same java code on a webpage, random(81) would I get the same answer '12345' ?
My second question regards the bitscrambler function you attached. Would it be correct to say that·this function will take the output of the random functon above, ex: '12345' and scramble it around so it becomes a different number, say: '8459'·?· -
Does the bitscrambler function also have to be written in java, or can that be used in pbasic as, is, and still return the same result on different machine platforms?
Thanks very much for your reply,
David
You can program the function in whatever language you want.
As the function only uses bitshifts and only swaps bits or nibbles,
the 16bit result should be identical in any language.
But note·that if you interpret the 16bit value as an integer
then be aware that the javelin uses little endian (as does pbasic)
but javelin treats it as a signed int, whereas pbasic treats it as an unsigned int.
The 16bit·pattern however is identical in both cases.
regards peter
Thanks very much for the clarification.
David
Great, of course, until you go to cash the winning $1M check, that is, and three very large men, in sunglasses, ask for you to come with them ... [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Expert in many fields, dumb as a stump with STAMP