[如何]在字符串末尾添加随机值 [英] [how to ] add random value at the end of string

查看:124
本文介绍了[如何]在字符串末尾添加随机值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我正在Windows窗体上做一个项目.我只从车辆号码生成条形码,但我担心,如果仅从车辆号码生成条形码,我在其他日子里也可能会再次获得旧收据.我想每天随机增加一些价值,以便不能使用旧的收据.我不能使用加密技术,因为它太长了,无法打印条形码,因为长度问题,我也无法使用日期,请向我提供一些帮助
bishnu karki

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

推荐答案

使用以下代码,它将为旧字符串添加0到1000之间的随机数:
Use the following code it will add a random number between 0 and 1000 to the oldstring:
Random r = new Random((int)DateTime.Now.Ticks);
string str = oldstring + r.Next(1000);


如果实际上是每天,则使用天数(
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.


引用该线程

http://stackoverflow.com/questions/1122483/c-sharp-random-string-generator [^ ]
Refer this thread

http://stackoverflow.com/questions/1122483/c-sharp-random-string-generator[^]


这篇关于[如何]在字符串末尾添加随机值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆