-1

I am working on a system where I need to select a leader(out of n nodes) randomly. The leader would change after each round (after the current leader has finished its task). All the nodes would be communicating with each other.

A re-election would take place in two conditions:

  1. The round is finished.
  2. The leader dies prematurely.

Are there any implementations of this idea for reference. Is doing so a good idea? Why? Should this situation be approached differently?

Swapnil Pandey
  • 577
  • 3
  • 8
  • 25
  • 1
    It's not at all clear what you're asking. Selecting a random leader from a list is trivially easy: just call your random number generator to get a number between 0 and n. What makes your problem different? – Jim Mischel Dec 27 '18 at 16:09

1 Answers1

0

As far as I have understood your question you need to select a different leader from your nodes Everytime so to do this you can put all the nodes in a queue and then find the length of queue and generate a random number from 0 to the queue length and name the node at this index as a leader when he dies or finished it's work you can remove this node from the queue and re elect your leader by the same process.Now the length is 1 less. Hope I have understood the question correctly.

Mohd Akbar
  • 111
  • 5