Fitri Halim
Fitri Halim

Reputation: 739

Generate a simple consistent pseudo-random number from same seed across different .Net version

I am developing software for a factory to track operators' work. The system generates coupons with a unique serial number (TaskId) for each task. Users scan a QR code or manually input the serial number (which is displayed in Base 26) into an Android app after completing a task.

To prevent exploitation where users insert neighboring IDs to access more coupons, I implemented a solution using C# Random function to append a two-character check at the end using the serial number as its seed. However, I discovered that the Random function may not generate the same number with the same seed across different .NET versions.

I am exploring alternatives to the Random function, considering CRC checks but concerned about generating neighboring values for neighboring seeds. I want a simple solution, as users may need to manually type the serial number.

What would be a better way to replace the Random function in this context, considering the simplicity of generated characters and ease of manual input?

The solution should be easy enough for computer to calculate, yet troublesome enough for mere humanbeing to guess (of course they can still brute force it, but each coupon only worth few cents).

Thanks in advance!

Upvotes: -1

Views: 141

Answers (1)

hatcyl
hatcyl

Reputation: 2352

If I understand correctly, you have sequential TaskIds (say 101) and you want to avoid someone just using "102" by adding extra random characters at the end (say 101G6 and 102FZ) and thus preventing them from knowing what the next valid TaskId is.

You can do this using a hash. A hash takes in "something" and outputs "something else" that looks completely random. It's deterministic, so it will always be the same even across different platforms/languages. It's used to protect passwords.

You could use for example the first two characters of the hash. You can also use a secret "salt" if you're afraid that your users might know that you hash.

Sample: Hash string in c#

Upvotes: 3

Related Questions