How can i get the candidates with a hash(number) from a list of nodes, algorithm?

53 Views Asked by At

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.

1

There are 1 best solutions below

0
CFrei On
  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)) }