code: def weighted(loads):
      """Pick two at random using inverse load as weight.
  
      Return the less loaded of the two.
      """
      # weight 0 a million times more than 1:
      weights = 1.0 / (1e-6 + numpy.array(loads))
      sums = weights.cumsum()
      t = sums[-1]
      x = random() * t
      y = random() * t
      idx = 0
      idy = 0
      while sums[idx] < x:
          idx += 1
      while sums[idy] < y:
          idy += 1
      if weights[idy] > weights[idx]:
          return idy
      else:
          return idx
  
imports: import time
  from collections import deque
  from random import randint, random
  from types import FunctionType
  import zmq
  from traitlets import Dict, Enum, Instance, Integer, List, observe
  from ipyparallel import Dependency, error, util
  from ipyparallel.controller.scheduler import Scheduler
label_desc: Use image node_id 4 for calling a global function with example usage: weighted(loads) and returns: idy, idx