Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends , i m doing a project on windows forms. i m generating a barcode from vehicle number only but i m afraid that if i generate it from vehicle number only i can get old receipts again for other days also. i want to add some value to it randomnly everyday so that the old receipts cannot be used. i cannot use encrytion techniques cuz its too long for me to print barcode for it neither i can use date due to length problem , please provide me with some help
bishnu karki
Posted
Comments
BillWoodruff 24-Oct-11 14:00pm    
It might help clarify your question if you say what the limit of the number of characters you can write out in the bar-code is.

And, just curious, if you take a vehicle number and add the current date and time to it, doesn't that create a unique code that will allow you to distinguish each receipt ?

I guess I'm asking why you are using a random number.

Use the following code it will add a random number between 0 and 1000 to the oldstring:
C#
Random r = new Random((int)DateTime.Now.Ticks);
string str = oldstring + r.Next(1000);
 
Share this answer
 
If it is literally per day, use the day number (the integer part of the result of DateTime.ToOADate[^]). If you want to obfuscate it, do something like XORing the day number with the vehicle number. If you want finer resolution, you can make use of the fractional part, or use DateTime.Now.Hour etc as part of the formula.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900