views:

53

answers:

2

Let me describe the system. There are several mobile devices, each independent from each other, and they are generating content for the same record id.
I want to avoid generating the same content for the same record on different devices, for this I though I would use a random and make it so too cluster the content pool based on these randoms.

Suppose you have choices from 1 to 100.

Day 1

  • Device#1 will choose for the record#33 between 1-10
  • Device#2 will choose for the record#33 between 40-50
  • Device#3 will choose for the record#33 between 50-60
  • Device#1 will choose for the record#55 between 40-50
  • Device#2 will choose for the record#55 between 1-10
  • Device#3 will choose for the record#55 between 10-20

  • Device#1 will choose for the record#11 between 1-10

  • Device#2 will choose for the record#22 between 1-10
  • Device#3 will choose for the record#99 between 1-10

Day 2

  • Device#1 will choose for the record#33 between 90-100
  • Device#2 will choose for the record#33 between 1-10
  • Device#3 will choose for the record#33 between 50-60

They don't have access to a central server.
Data available for each of them:

  • IMEI (unique per mobile)
  • Date of today (same on all devices)
  • Record id (same on all devices)

What do you think, how is it possible?

ps. tags can be edited

+1  A: 

If each device has a unique DeviceID (maybe based on the hardware serial number or something) you could use that instead of these random number schemes. Would keep things much simpler.

FrustratedWithFormsDesigner
How would that be in code?
Pentium10
+3  A: 

I agree with AakashM and Frustrated. First can you guarantee that the number of devices is greater than the range of generated data? In fact to be "Random" you really need to have twice the generated content as devices, otherwise at least one device will have to "randomly choose" between one choice. That stated since the IMEI is the only unique data based on the device you will have to use that in your algorithm. The other problem (I suspect) is that the device IDs are not necessarily evenly distributed so any potential mapping of a device ID to a data block would potentially lead to overlap (unless you have a very large range of data to select from) or the values generated would not be evenly distributed across the pool of devices.

That said here is a rough algorithm:

  1. Create a mapping of the IMEI to an integer (i.e. some kind of hash)
  2. Rotate that integer based on the date and the size of possible values generated in step
  3. Map the number resultant from 2 to a range of data values based on the ratio of IMEIs to value range created by step #1.
  4. Use the standard random number to select something from that range

A simple example using the IMEI as a single byte and a data range of 0->2559:

  1. Mapping is direct based on IMEI, so base = IMEI
  2. Date translation is based on #of days since epoch. For this example say 700 then base = (9(original base: Mapped IMEI)+700(# of days)) % 255(range of mapped IMEI value) = 199
  3. Data range is 10 times mapped value range, so each block may use 10 values, resultant data range from 2 becomes 1990 ->1999 (inclusive).
  4. Select a standard random value in the block data range (i.e. 4, as chosen by fair dice roll) value = 1990+4=1994.

Finally if you want the ranges to differ based on the record you could use that as a second offset as was done in step #2.

M. Jessup
+1 This is pretty much exactly what I was thinking of.
AakashM