Due to the specifics of the project I'm working on I need a way to mint token IDs in a random fashion rather then sequentially. The requirements for randomness are not particularly strict, and
block.timestamp + totalSupply() is enough for this particular case.
The problem comes as the amount of minted tokens increases. Since we need to ensure a new token ID was not minted yet, a
!_exists(tokenId) lookup is required. But eventually the number of these calls becomes so big as to exhaust the gas limit.
(I know you might ask why not randomize the assets mapped to these IDs instead? But I wouldn't have to ask you this question if this would be possible — it is a strict project requirement.)
So the question is: Is there a more computationally efficient way to do this? Or a sequential lookup is the only solution which isn't going to work?