Reputation:
I am creating a simple react native social media app, and I need each user to have a consistent number between 0-100 that will be used to give them a consistent color in all of their posts. I don't know an easy way to create a number that always stays the same each time you open the app. What would you reccomend?
Upvotes: 0
Views: 67
Reputation: 2839
I recommend you hash any info of your users whose values are well distributed (names, ids, ...). Then bring back this hash value between 0 and 100 with a simple modulo.
And just change the end by:
return hash % 101;
Upvotes: 1