What is the range? and, is Zero a valid random number?
Create an array with 16 elements,
Set all 16 elements to zero, (I am assuming zero is not a valid random number)
Generate a random number check that it does not exist in the array, if unique - put into element 1
Repeat above put valid result into the next available element that is zero, stopping after the 16th element is not zero.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you mean 16 byte numbers that are all different? unique meaning.
dimnums(16)asbyteforc1=1to16nums(c1)=randomnext
gcb would not repeat a number in 16 array. It would be the same numbers every time... from gcb help.
;----------------------------------------------
Random
Syntax:
var=Random
Command Availability:
Available on all microcontrollers
Explanation:
The Random function will generate a pseudo-random number between 0 and 255 inclusive.
The numbers generated by Random will follow the same sequence every time, until Randomize is used.
Example:
'Set chip model
#chiptiny2313, 1'Use randomize, with the value on PORTD as the seedRandomizePORTD'Generate random numbers, and output on PORTBDoPORTB=RandomWait1sLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@JackHoffnung ... An array of 16 different numbers is a challenge. if you use a port like a-d to use the noise for a truly random value.
The 16 different numbers 1 to 255 is my latest challenge. It's not as easy as you think but could be done efficiently.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am generating a set of 16 bytes "randomly" and want to determine if all are unique values. Anyone know of a simple way to do this?
Jack,
What is the range? and, is Zero a valid random number?
Create an array with 16 elements,
Set all 16 elements to zero, (I am assuming zero is not a valid random number)
Generate a random number check that it does not exist in the array, if unique - put into element 1
Repeat above put valid result into the next available element that is zero, stopping after the 16th element is not zero.
Thanks so much; this is the help I needed.
Do you mean 16 byte numbers that are all different? unique meaning.
gcb would not repeat a number in 16 array. It would be the same numbers every time... from gcb help.
;----------------------------------------------
Random
Syntax:
Command Availability:
Available on all microcontrollers
Explanation:
The Random function will generate a pseudo-random number between 0 and 255 inclusive.
The numbers generated by Random will follow the same sequence every time, until Randomize is used.
Example:
That is true Stan. For a given RANDOMISE instruction the next 16 RANDOMs would be different.
Thanks Stan and Anobium; this information will be very helpful with my project!
@JackHoffnung ... An array of 16 different numbers is a challenge. if you use a port like a-d to use the noise for a truly random value.
The 16 different numbers 1 to 255 is my latest challenge. It's not as easy as you think but could be done efficiently.