def _s5(Xs): rand = random.random n = _xlen(Xs) print(n) return [((x0 + rand()) / n[0], (x1 + rand()) / n[1], (x2 + rand()) / n[2], (x3 + rand()) / n[3], (x4 + rand()) / n[4]) for x0 in Xs[0] for x1 in Xs[1] for x2 in Xs[2] for x3 in Xs[3] for x4 in Xs[4]]
def _s10(Xs): rand = random.random n = _xlen(Xs) print(n) return [((x0 + rand()) / n[0], (x1 + rand()) / n[1], (x2 + rand()) / n[2], (x3 + rand()) / n[3], (x4 + rand()) / n[4], (x5 + rand()) / n[5], (x6 + rand()) / n[6], (x7 + rand()) / n[7], (x8 + rand()) / n[8], (x9 + rand()) / n[9]) for x0 in Xs[0] for x1 in Xs[1] for x2 in Xs[2] for x3 in Xs[3] for x4 in Xs[4] for x5 in Xs[5] for x6 in Xs[6] for x7 in Xs[7] for x8 in Xs[8] for x9 in Xs[9]]
def generate(self): self.clear() firstR = 1 + rand(self.rows - 2) firstC = 1 + rand(self.cols - 2) self.map[firstR][firstC] = " " history = [(firstR, firstC)] adjacent = [(-1, 0), (0, 1), (1, 0), (0, -1)] diagonals = [(-1, 1), (1, 1), (1, -1), (-1, -1)] while len(history): r, c = history.pop() nextMoves = [] # type: List[Tuple[int, int]] for move in adjacent: nextR = r + move[0] nextC = c + move[1] # move is valid if it is in bounds and does not connect to an already open space valid = True if nextR > 0 and nextR + 1 < self.rows and nextC > 0 and nextC + 1 < self.cols and self.map[ nextR][nextC] == "#": # check if any of the spaces adjacent to the prospective move are already open for move2 in adjacent: if nextR + move2[0] == r and nextC + move2[1] == c: continue # Don't care about the space we're currently at if self.map[nextR + move2[0]][nextC + move2[1]] == " ": valid = False else: for diagonalMove in diagonals: if self.map[nextR + diagonalMove[0]][nextC + diagonalMove[1]] == " " \ and self.map[nextR][nextC + diagonalMove[1]] == "#" \ and self.map[nextR + diagonalMove[0]][nextC] == "#": valid = False else: valid = False # Out of bounds if valid: nextMoves.append((nextR, nextC)) if len(nextMoves): nextR, nextC = pick(nextMoves) history.append((r, c)) self.map[nextR][nextC] = " " history.append((nextR, nextC))
def _s7(Xs): rand = random.random n = _xlen(Xs) print(n) return [((x0 + rand()) / n[0], (x1 + rand()) / n[1], (x2 + rand()) / n[2], (x3 + rand()) / n[3], (x4 + rand()) / n[4], (x5 + rand()) / n[5], (x6 + rand()) / n[6]) for x0 in Xs[0] for x1 in Xs[1] for x2 in Xs[2] for x3 in Xs[3] for x4 in Xs[4] for x5 in Xs[5] for x6 in Xs[6]]
def printVals(page_array, frames, algorithms): page_string = "Page Reference String:\n" for page in page_array: page_string = page_string + page + " " print page_string print "Number of Frames: " + str(frames) for alg in algorithms: if alg == "FIFO": fifo(page_array, frames) elif alg == "LRU": lru(page_array, frames) elif alg == "LFU": lfu(page_array, frames) elif alg == "OPT": opt(page_array, frames) elif alg == "RAND": rand(page_array, frames) elif alg == "MFU": mfu(page_array, frames) elif alg == "MRU": mru(page_array, frames)
import array as arr import random as rand floats = arr('d', (rand() for i in range(10**7))) print(floats[-1])
surface = subplot3d.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=matplotlib.cm.coolwarm, linewidth=0.1) plt.show() Another way to display this same data is *via* a contour plot. plt.contourf(X, Y, Z, cmap=matplotlib.cm.coolwarm) plt.colorbar() plt.show() ## Scatter plot To draw a scatter plot, simply provide the x and y coordinates of the points. from numpy.random import rand x, y = rand(2, 100) plt.scatter(x, y) plt.show() You may also optionally provide the scale of each point. x, y, scale = rand(3, 100) scale = 500 * scale ** 5 plt.scatter(x, y, s=scale) plt.show() And as usual there are a number of other attributes you can set, such as the fill and edge colors and the alpha level. for color in ['red', 'green', 'blue']: n = 100 x, y = rand(2, n)
# openssl enc -aes-256-cbc -salt def solution(n): d = [0] * 30 l = 0 while (n > 0): d[l] = n % 2 n //= 2 l += 1 print(d, l, "L stores strlen") for p in range(1, l + 1): # L stores strlen, But why l+1? ok = True for i in range(l - p): # doubt on l-p, should be just l if d[l - i] != d[l - i - p]: print(l - i, l - i - p, d[l - i], d[l - i - p], "i=", i, p) ok = False break if ok: return p return -1 import rand print(solution(rand()))
def gen_cqt(**kwargs): opt._parse(kwargs) gen_rand = rand(opt.mode) gen_rand.gen_cqt()
def gen(**kwargs): opt._parse(kwargs) gen_rand = rand(opt.mode) gen_rand.gen_dataset()
def _s3(Xs): rand = random.random n = _xlen(Xs) print(n) return [((x0 + rand()) / n[0], (x1 + rand()) / n[1], (x2 + rand()) / n[2]) for x0 in Xs[0] for x1 in Xs[1] for x2 in Xs[2]]
def _s2(Xs): rand = random.random n = _xlen(Xs) print(n) return [((x0 + rand()) / n[0], (x1 + rand()) / n[1]) for x0 in Xs[0] for x1 in Xs[1]]
def _s1(Xs): rand = random.random n = _xlen(Xs) print(n) return [((x0 + rand()) / n[0], ) for x0 in Xs[0]]