0

I have a list of nodes-NodeList(each of them is different). and i has a number-N
Here we want to select some nodes as candidate from the list(needed more than half).
Is there any algorithm to achieve this goal. There are some tips:
1. same N(we call it seed), same selection result
2. the number of candidate must be more than half of the list size
3. different seed, different result(as far as possible).

For example:
List of nodes(NodeList) : [nodeA, nodeB, nodeC,...,nodeZ], the size of NodeList is 26. Each of node is a address(in akka, you can image it is a string).
And i need a algorithm.
Input:

  • Seed: a number(int)
  • NodeList : List of nodes

Output: - NodeListResult: according to the seed, we select some nodes from NodeList. maybe [nodeA, nodeB, nodeD, ..., nodeZ]. The size of NodeListResult must be greater than the half of NodeList's size.

kami
  • 71
  • 1
  • 6
  • 1
    Can you post a few examples of expected input and output (and explanation) to show what you mean? Your explanation is really hard to understand. – Bernhard Barker Jun 07 '17 at 10:07
  • for example: List of nodes(NodeList) : [nodeA, nodeB, nodeC,...,nodeZ], the size of NodeList is 26. Each of node is a address(in akka, you can image it is a string). And i need a algorithm. – kami Jun 08 '17 at 00:49
  • Treat the `Seed` as a mixed-radix number. See: *reservoir sampling*. – joop Jun 08 '17 at 09:27

1 Answers1

0
  1. use your seed N to initialize a random number generator
  2. halfSize = NodeList / 2
  3. newLength = halfSize * randomNumber() + halfSize
  4. newNodes = []
  5. for(i over newLength) { nowNodes.push(NodeList.removeElement(randomNumber() * NodeList.size)) }
CFrei
  • 3,552
  • 1
  • 15
  • 29