user8749566
user8749566

Reputation:

How to differentiate each user in React Native?

Problem

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

Answers (1)

RaphaMex
RaphaMex

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.

Read this: Generate a Hash from string in Javascript/jQuery

And just change the end by:

return hash % 101;

Upvotes: 1

Related Questions