random

Generate high contrast random color using PHP

不羁岁月 提交于 2020-01-06 07:57:26
问题 I need to generate random colors for all the users in the system. The trick is that 2 users cant have very similar colors, they need to be distinguishable. I have the code to generate random colors given the original mix color but cant find a way to generate random colors with high contrast using only PHP public static function generateRandomColor($rgb) { $red = rand(1, 256); $green = rand(1, 256); $blue = rand(1, 256); if (! empty($rgb)) { $red = ($red + $rgb['red']) / 2; $green = ($green +

Randomly number selector from a given list of numbers [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-01-06 07:56:08
问题 This question already has answers here : Generate numbers randomly from a set? (2 answers) Closed 10 months ago . I have given list of numbers, x=[x1, x2, x3, x4, x5, x6]; non_zero=find(x); I want Matlab to randomly select anyone among elements of 'non_zero' at a time. I searched online but there is no such function available to provide my required results. 回答1: You could use the function randi to randomly select an integer from the set of valid indices. x=[x1, x2, x3, x4, x5, x6]; non_zero

Understanding srand(time(0)) behaviour [duplicate]

家住魔仙堡 提交于 2020-01-06 06:52:32
问题 This question already has answers here : C++ srand() function in loop [duplicate] (1 answer) srand(time(NULL)) doesn't change seed value quick enough [duplicate] (6 answers) Closed last year . Given below is my attempt to create a simple high-low game. I just don't understand why the code given below behaves differently when I place the srand(time(0)) inside the do-while loop, i.e, why does the modified code generate the same random number in each iteration of the loop? #include<iostream>

Python Tkinter - Dictionary with Buttons - how do you disable them?

荒凉一梦 提交于 2020-01-06 06:51:07
问题 I created a 7x7 field of buttons with a dictionary. Problem 1: I need to disable a User-Input amount of buttons randomly. The user writes a number x and x buttons will be blocked, but my program has to choose them randomly... Problem 2: The Rest of the buttons are usable. But if you click one, they will change the color and get state = tk.DISABLED . How do I do all that with a dictionary full of buttons? buttons = {} for x in range(0, 7): for y in range(0, 7): buttons[tk.Button(frame_2,

Need a repeatable random array shuffle using a key

≯℡__Kan透↙ 提交于 2020-01-06 06:39:06
问题 I am looking to randomly shuffle a list/array using a key. I want to be able to repeat the same random order using the key. So I will randomly generate a numeric key from say 1 to 20 then use that key to try and randomly shuffle the list. I first tried just using the key to keep iterating through my list, decrementing the key until=0, then grabbing whatever element I am on, removing it and adding it to my shuffled array. The result is kind of random but when the arrays are small (which most

C++ generating random numbers-1

戏子无情 提交于 2020-01-06 05:48:04
问题 int main() { srand((unsigned)time(0)); int random_integer; int lowest=0, highest=10; int range=(highest-lowest)+1; for(int index=0; index<20; index++){ random_integer = (rand() % range) + lowest/(RAND_MAX + 1.0); cout << random_integer << endl; } } I am getting the output from 0 to 10, 11 numbers, but I don't want to get number 10, just numbers 0 to 9, that means 10 random numbers, what should I do? 回答1: Modulo operation x % c; returns the remainder of division of number x by c . If you do x

Random assign methods into inputs

微笑、不失礼 提交于 2020-01-06 05:44:05
问题 For each of the inputs (name, phoneno), I am using Random Number Generator to assign the inputs to a method. My goal is to get all possible combinations of methods to an input. Below are my codes. What if I have 1000 of inputs and methods? Is there any efficient way to this this? public static void main(String[] args) { for (int i = 0; i < 9; i++) { Random myRand = new Random(); int randomInteger = myRand.nextInt(10); if (randomInteger == 0) { name = methodA(); phoneno = methodA(); } else if

How to activate randomized filenames in powermail

丶灬走出姿态 提交于 2020-01-06 05:34:06
问题 i have a form where user could upload files. There are 3 files they could upload and each of them need to have an unique name. So even the person upload the same file everytime i neet different names for it in the email, i get from the form. So i try to use randomizeFileName. https://github.com/einpraegsam/powermail/blob/develop/Configuration/TypoScript/Main/setup.txt#L538 Cause i dont have the randomizeFilename in my constants.txt it try to enter it in my setup.txt with a real value. # File

generating random number with normal distribution in VBA- Runtime error ‘1004’

走远了吗. 提交于 2020-01-06 05:27:10
问题 I have problem with generating random numbers with normal distribution in VBA. I’m working on NSGAII. I use “Application.WorksheetFunction.Norm_Inv (Rnd, Mean, Deviation)” to generate random numbers with normal distribution. But I this error raises: Runtime error ‘1004’: Unable to get the Norm_Inv property of the worksheetfunction class How can I fix this error? I’ve already used this code in another simple macro and it works. But by using this code in NSGAII code there is an error! (Large

Auto-fill matrix without row-repetitions

我与影子孤独终老i 提交于 2020-01-06 05:10:06
问题 I have a series of numbers: test = [1 1 1 2 2 2 3 3 3 4 4 4 5 5 5] which I want to randomely fill into a 3x5 matrix without having the same number in the same row. How can I do this in matlab? Potentially I could randomize the test vector and fill it into the 5x3 matrix but I don't know how to do this without getting the same number in the same row. 回答1: If you want to fill a 3-by-5 matrix with all of the values in test , making sure each row has no repeated values, you can do this very