Randomized version of `zoom`.
166616
def rand_zoom(scale:uniform=1.0, p:float=1.):
    ""
    return zoom(scale=scale, **rand_pos, p=p)
556655
def select(self, **kws):
        '''
            
        '''
        lst = [i for i in self.values() if i.select(**kws)]

        random.shuffle(lst)

        return lst
1029743
public static <T> void randomDraw(List<T> dataSet, int numSample,
									  List<T> initialSample, Random rand) {
		initialSample.clear();

		for (int i = 0; i < numSample; i++) {
			// index of last element that has not been selected
			int indexLast = dataSet.size()-i-1;
			// randomly select an item from the list which has not been selected
			int indexSelected = rand.nextInt(indexLast+1);

			T a = dataSet.get(indexSelected);
			initialSample.add(a);

			// Swap the selected item with the last unselected item in the list. This way the selected
			// item can't be selected again and the last item can now be selected
			dataSet.set(indexSelected,dataSet.set(indexLast,a));
		}
	}
725711
def seed_zoom(seeds, zoom):
    
    # import scipy
    # loseeds=seeds
    labels = np.unique(seeds)
    # remove first label - 0
    labels = np.delete(labels, 0)
    # @TODO smart interpolation for seeds in one block
    #        loseeds = scipy.ndimage.interpolation.zoom(
    #            seeds, zoom, order=0)
    loshape = np.ceil(np.array(seeds.shape) * 1.0 / zoom).astype(np.int)
    loseeds = np.zeros(loshape, dtype=np.int8)
    loseeds = loseeds.astype(np.int8)
    for label in labels:
        a, b, c = np.where(seeds == label)
        loa = np.round(a // zoom)
        lob = np.round(b // zoom)
        loc = np.round(c // zoom)
        # loseeds = np.zeros(loshape)

        loseeds[loa, lob, loc] += label
        # this is to detect conflict seeds
        loseeds[loseeds > label] = 100

    # remove conflict seeds
    loseeds[loseeds > 99] = 0

    # import py3DSeedEditor
    # ped = py3DSeedEditor.py3DSeedEditor(loseeds)
    # ped.show()

    return loseeds
1101578
def random_draw(self, size=None):
        
        return scipy.asarray([scipy.stats.lognorm.rvs(s, loc=0, scale=em, size=size) for s, em in zip(self.sigma, self.emu)])
953450
def numberOfTilesAtZoom(self, zoom):
        ""
        [minRow, minCol, maxRow, maxCol] = self.getExtentAddress(zoom)
        return (maxCol - minCol + 1) * (maxRow - minRow + 1)
828266
def randomPositionsMask(mask, nside_pix, n):
    
    
    npix = len(mask)
    nside = hp.npix2nside(npix)

    # Estimate the number of points that need to be thrown based off
    # coverage fraction of the HEALPix mask
    coverage_fraction = float(np.sum(mask)) / len(mask) 
    n_throw = int(n / coverage_fraction)
        
    lon, lat = [], []
    latch = True
    count = 0
    while len(lon) < n:
        lon_throw = np.random.uniform(0., 360., n_throw)
        lat_throw = np.degrees(np.arcsin(np.random.uniform(-1., 1., n_throw)))

        pix = ugali.utils.healpix.angToPix(nside, lon_throw, lat_throw)
        cut = mask[pix].astype(bool)

        lon = np.append(lon, lon_throw[cut])
        lat = np.append(lat, lat_throw[cut])

        count += 1
        if count > 10:
            raise RuntimeError('Too many loops...')

    return lon[0:n], lat[0:n]
965959
def random_crop_and_flip(x, pad_rows=4, pad_cols=4):
  """"""
  rows = tf.shape(x)[1]
  cols = tf.shape(x)[2]
  channels = x.get_shape()[3]

  def _rand_crop_img(img):
    """Randomly crop an individual image"""
    return tf.random_crop(img, [rows, cols, channels])

  # Some of these ops are only on CPU.
  # This function will often be called with the device set to GPU.
  # We need to set it to CPU temporarily to avoid an exception.
  with tf.device('/CPU:0'):
    x = tf.image.resize_image_with_crop_or_pad(x, rows + pad_rows,
                                               cols + pad_cols)
    x = tf.map_fn(_rand_crop_img, x)
    x = tf.image.random_flip_left_right(x)
  return x
737812
def change_zoom(self, zoom):
        ''''''
        state = self.state
        if self.mouse_pos:
            (x,y) = (self.mouse_pos.x, self.mouse_pos.y)
        else:
            (x,y) = (state.width/2, state.height/2)
        (lat,lon) = self.coordinates(x, y)
        state.ground_width *= zoom
        # limit ground_width to sane values
        state.ground_width = max(state.ground_width, 20)
        state.ground_width = min(state.ground_width, 20000000)
        self.re_center(x,y, lat, lon)
356521
def _random_fill(self):
        """"""
        a = self._array
        for p, tile in self.positions_with_tile():
            if tile.is_blank():
                a[p] = Tile.random_tile()
1109872
def random(cls):
        """"""
        axis = random_unit()
        angle = np.random.uniform(0,2*np.pi)
        invert = bool(np.random.randint(0,2))
        return Rotation.from_properties(angle, axis, invert)
29764
def create(deg, p=0.75, mode='x', tags=None):
    
    return RandomRotate(deg, p, mode, tags)
1261899
def shuffle_sattolo(items):
    """"""
    _randrange = random.randrange
    for i in reversed(range(1, len(items))):
        j = _randrange(i)  # 0 <= j < i
        items[j], items[i] = items[i], items[j]
1123267
def random_size_crop(src, size, min_area=0.25, ratio=(3.0/4.0, 4.0/3.0)):
    """"""
    h, w, _ = src.shape
    area = w*h
    for _ in range(10):
        new_area = random.uniform(min_area, 1.0) * area
        new_ratio = random.uniform(*ratio)
        new_w = int(new_area*new_ratio)
        new_h = int(new_area/new_ratio)

        if random.uniform(0., 1.) < 0.5:
            new_w, new_h = new_h, new_w

        if new_w > w or new_h > h:
            continue

        x0 = random.randint(0, w - new_w)
        y0 = random.randint(0, h - new_h)

        out = fixed_crop(src, x0, y0, new_w, new_h, size)
        return out, (x0, y0, new_w, new_h)

    return random_crop(src, size)
855445
def _shuffle(y, labels, random_state):
    """"""
    if labels is None:
        ind = random_state.permutation(len(y))
    else:
        ind = np.arange(len(labels))
        for label in np.unique(labels):
            this_mask = (labels == label)
            ind[this_mask] = random_state.permutation(ind[this_mask])
    return y[ind]
509114
def sample_view(min_dist, max_dist=None):
  '''
  '''
  if max_dist is None:
    max_dist = min_dist
  dist = np.random.uniform(min_dist, max_dist)
  eye = np.random.normal(size=3)
  eye = normalize(eye)*dist
  return lookat(eye)
1013191
def randomToggle(self, randomize):
        """"""
        if randomize:
            self._stim.setReorderFunc(order_function('random'), 'random')
        else:
            self._stim.reorder = None