There are x number of users.

Every time a user clicks a button, they give another random user a high-five.

They get rewarded for giving the other user a high 5, and there is then an increase in the potential for them to receive a high five from others.

Each user may only high-five each other user once per day.(users may give high fives to other users that high fived them that day)

my idea was to store numbers to each user, and for every time they click, they get a new additional number stored to them...

Then rng picks a number(out of the range of numbers that has been stored to all users) and the user with that number designated to him gets high fived and that number and all other numbers designated to that same user drops out of rng's potential generation.

But this seems slow and sloppy to me...
Does anyone have any better ideas?

Edited by oldezwe: n/a

5 Years
Discussion Span
Last Post by Philippe.Lahaie

How about have an array which index corresponds to a particular user, say an element will contain a user_id. Resize array when you want a user to gain more probability and give that resized space another user_id. rng the given index range.

You can either log the indexes that correspond to a user you want to reject, or store these information in the elements themselves. Maybe the elements will just point to the user information - a master user_id.


The only part you seem to need help on is how to properly "increase in the potential for them to receive a high five from others ". The other problem is fairly trivial.

To increase a user's potential of receiving a high-five you first have to note that to increase the probability of a user you need to uniformly decrease the probability of other users and add that to the current user. Also when picking the person to high-five you need to take into account the probability of picking each person. The easiest way to do this is to use some sort of range concept. For example
user one has a range from [1-50] and user two has range from [51,100], so you get the maximum range which is from user two with value of 100, then you get the minimum range from the users, which user one has with a value of 1, then you generate a random number from min to max. And check which user's range it falls under. Furthermore, you then increase the range for whichever user gave the high-five. For example, if user one gave high five to user two, then you could change the range of user on from [1-50] to [1-51] and then adjust the range of user two to [52-100]. Remember these range represents the probability so you need to make sure that add up correctly.


how about this...

each user will have an ID number

each user will have an array saved to them, starting with 1 element, their
id number

each time they give others a high 5 they will gain a certain amount of their id number
to their array

after 1 high 5(user id# 34):[34]
after 4 high 5s(user id# 34):[34, 34, 34, 34]

All arrays are saved into one larger array

A random number generator chooses a number from the larger array

if that number is chosen, that number along with numbers of the same
value are dropped from the array for that day

would this be more efficient than the previous suggestion?


So lets break it down into steps:

1. X number of users
2. Give a random a high five.
3. Give a reward for high five.
4. Increase chance to get high five.

Here is how we could store the text file:
name 1|0|1
name 2|0|1
name 3|0|1
name 4|0|1

The first column is the persons name, the second column is if they have high-fived anyone today (0 for no, 1 for yes) and the last column is the chance to be high-fived.

So lets go through the steps again:
1. X number of users (get number of all users)
2. Give a random a high five. (generate a random number and high-five them. change the second column to a 1)
3. Give a reward for high five.
4. Increase chance to get high five. (change the last column)

So this is all I could think of, hope it helps!


what you could do is keep "points" for each player which determines their chances of getting picked.

arrayPoints starts with 10 in every field and everytime a user high fives someone, the field corresponding for that player increases by "x" points, if you wanna double his chances you would add 10 or just give him 10% more chances you would add 1!

then whenever some1 high fives you calculate the sum of everyones points in the points array , generate a number from 0 to that sum , then go through the array and substract each players points to the generated number. when the generated number reaches 0 or less you have a winner, the current point field is the current high fived user, according the user throwing the high five has not high fived that user today.

ideally, you would implement all that in a better way with a player or user class wich would contain the "points" / "chances" , their id , and their array or vector or whatever data structure you feel would be best to keep track of who they highfived that day ...

this way you get to keep track of everything with a single array/structure of users

let us know how you choose to do it! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.