I need to generate a number that is unique for the current day, I'm bound to use short data type and I tought to use hour/minute to achieve that. This is my VB code:
Dim ora As String = dataora.Substring(6, 2) 'es. 07
Dim minuti As String = dataora.Substring(8, 2) 'es 14
Dim parteOra = ora * 1000
Dim parteMinuti = rando.Next(0, 708)
Dim parteFinale = rando.Next(0, 9000)
Dim CUL as short = CShort(parteOra + (minuti + parteMinuti) + parteFinale)
Knowing that short data type manage a 0-32767 range (from 0 up, I can't use negative) my question is: with the code above can I be 100% sure that in the same day I will always have an unique number?
My logic is:
- hour in 24h format is unique 0-23 number
- minutes is unique 0-59 number in the same hour
- parteOra can go from 0 to 23000
- minuti + parteMinuti can go from 0 to 767
- parteFinale can go from 0 to 9000
- putting all togheter I should have a range from 0 to 32767
Aucun commentaire:
Enregistrer un commentaire