Generate Unique Values

Authors

Generating Unique Values

How to write a generator that produces unique values?

Normally, if you need unique values, there is some notion of 'state', only when
there is state, it is important that a value differs from a previous value. For example, if you send a sequence of messages to a server and each message needs
a unique tag, different from previous tags. The server 'remembers' the state and
if you want to perform positive testing, you may not want to send the same
tag twice.

It may be worth considering to just create a deterministic list and take consecutive values from that list.

unique() ->
lists:seq(0,100).

More advanced, if you do not use integers as values, you could create the list
and filter out the values that occur more than once.

What if one wants to create a fixed amount of unique values, say a vector of
length N. Once again, you may be happy with lists:seq(1,N), if you have
are happy with integers. You can even write a function from integers to your
actual value that generates a unique value depending on your input.