random

Creating a grid layout that holds 100 buttons with 80 empty buttons and 20 random treasure buttons

≯℡__Kan透↙ 提交于 2021-02-11 16:12:40
问题 We are working on a Treasure Hunt game in class as a project. Below is the code that we have so far. I need to randomize where the Treasure Buttons are. My question is: Do I need to create an array that will hold EmptyButton and TreasureButton and then call Random on it or is there a way to create a random layout within the TreasureButton class? Here is our code so far public class TreasureGame { // has-a number of tries private int numberOfTriesLeft = 50; //has-a number of hidden treasure

Program that generates 20 random numbers and search the array for a number

我是研究僧i 提交于 2021-02-11 15:53:33
问题 I want to make a program that generates 20 random numbers and search the array for a number. If one of the 20 random numbers was typed in the input the output should say "it is here". If the number is not in the ReadLine it should say"Yes it is there".I want to know how to make all 20 random numbers to be able to search. The code right now can only search the number on the right. Even if the input is one of the 20 random numbers except for the one on the right it would say "No it is not here.

bash grep 'random matching' string

余生颓废 提交于 2021-02-11 15:19:32
问题 Is there a way to grab a 'random matching' string via bash from a text file? I am currently grabbing a download link via bash, curl & grep from a online text file. Example: DOWNLOADSTRING="$(curl -o - "http://example.com/folder/downloadlinks.txt" | grep "$VARIABLE")" from online text file which contains http://alphaserver.com/files/apple.zip http://alphaserver.com/files/banana.zip where $VARIABLE is something the user selected. Works great, but i wanted to add some mirrors to the text file.

rand() gives almost the same number every time

不打扰是莪最后的温柔 提交于 2021-02-11 14:55:58
问题 I'm learning C and I want to generate a number between 0 and 6400. This is the code I came up with: #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { srand(time(0)); int i = (rand() % 6401); printf("Random number between 0 and 6400: %d\n", i); return 0; } When I compile and run this code from the command line I get some very weird results: K:\C\Labo\Oefeningen 2019>a Random number between 0 and 6400: 6282 K:\C\Labo\Oefeningen 2019>a Random number between 0 and 6400: 6282 K

numpy: Print matrix with random elements, columns and rows

旧街凉风 提交于 2021-02-11 14:30:19
问题 I want a matrix to be printed with random columns(0, 9) and random rows(0, 9) with random elements(0, 9) Where (0, 9) is any random number between 0 and 9. 回答1: If what you're looking for is a 10x10 matrix filled with random numbers between 0 and 9, here's what you want: # this randomizes the size of the matrix. rows, cols = np.random.randint(9, size=(2)) # this prints a matrix filled with random numbers, with the given size. print(np.random.randint(9, size=(rows, cols))) Output: [[1 7 1 4 4

Multithread computation with R: how to get all different random numbers?

梦想与她 提交于 2021-02-11 14:29:57
问题 Anyone knows how to get all the random numbers different in the following code? E.g. with doRNG package? I don't care about reproducibility. Edit: Duplicates by pure chance are accepted. rm(list = ls()) set.seed(666) cat("\014") library(plyr) library(dplyr) library(doRNG) # ====== Data Preparation ====== dt = data.frame(id = 1:10, part = rep("dt",10), HG = c(1,3,6,NA,NA,2,NA,NA,NA,NA), random = NA) # ====== Set Parallel Computing ====== library(foreach) library(doParallel) cl = makeCluster(3,

Python switching multiple positions in string each to multiple letters

亡梦爱人 提交于 2021-02-11 14:20:20
问题 I am trying to write a python code that finds restriction enzyme sites within a sequence of DNA. Restriction enzymes cut at specific DNA sequences, however some are not so strict, for example XmnI cuts this sequence: GAANNNNTTC Where N can be any nucleotide (A, C, G, or T). If my math is right thats 4^4 = 256 unique sequences that it can cut. I want to make a list of these 256 short sequences, then check each one against a (longer) input DNA sequence. However, I'm having a hard time

use javascript to write a random <script>

给你一囗甜甜゛ 提交于 2021-02-11 13:35:32
问题 How do I add a random 1 of 4 pre-defined <script> s to a webpage? i.e. A 3rd party tool has 4 e-book download modal forms that are generated by a unique <script> (1 for each e-book). I want to randomly add 1 of these <script> s to the page, so that on each page load, a different e-book download modal form is displayed. How would I do this? I've tried: var min=1; var max=4; var random = Math.random() * (+max - +min) + +min; switch ($random) { case 1: document.write(<script src=""></script>)

How to generate random values in range (-1, 1) such that the total sum is 0?

。_饼干妹妹 提交于 2021-02-11 13:01:39
问题 If the sum is 1, I could just divide the values by their sum. However, this approach is not applicable when the sum is 0. Maybe I could compute the opposite of each value I sample, so I would always have a pair of numbers, such that their sum is 0. However this approach reduces the "randomness" I would like to have in my random array. Are there better approaches? Edit: the array length can vary (from 3 to few hundreds), but it has to be fixed before sampling. 回答1: You could use sklearns

How to generate random values in range (-1, 1) such that the total sum is 0?

霸气de小男生 提交于 2021-02-11 12:59:05
问题 If the sum is 1, I could just divide the values by their sum. However, this approach is not applicable when the sum is 0. Maybe I could compute the opposite of each value I sample, so I would always have a pair of numbers, such that their sum is 0. However this approach reduces the "randomness" I would like to have in my random array. Are there better approaches? Edit: the array length can vary (from 3 to few hundreds), but it has to be fixed before sampling. 回答1: You could use sklearns