Posts

Showing posts with the label random

How can i use ' ++ i ' inside this situation?

Image
Clash Royale CLAN TAG #URR8PPP How can i use ' ++ i ' inside this situation? I want to draw a random name for an event where users can win items specified by their ID (1,2,3 etc.). The random name part is ok by now but how can i display the result like: The ID : 1 winner is: 'the random name' The ID : 2 winner is: 'the random name' etc... till ID : 27 static void Main(string args) { string Names = { "Erik", "Levente", "Noel", "Áron", "Krisztián", "Kristóf", "Bence", "Roland", "Máté", "László", "Bálint" , "Regina", "Brigitta", "Gréta", "Hédi", "Hanna", "Boglárka", "Jázmin", "Réka", "Alexandra", "Rebeka", "Lili", "Luca", "Zsófi"}; List<string> alreadyUsed = new List<string>(); Ra...

In this situation how can i display the results without duplicatin ?:)

Image
Clash Royale CLAN TAG #URR8PPP In this situation how can i display the results without duplicatin ?:) Describe it on a baby level im so beginner... static void Main(string args) { string Names = { "Erik", "Levente", "Noel", "Áron", "Krisztián", "Kristóf", "Bence", "Roland", "Máté", "László", "Bálint" , "Regina", "Brigitta", "Gréta", "Hédi", "Hanna", "Boglárka", "Jázmin", "Réka", "Alexandra", "Rebeka", "Lili", "Luca", "Zsófi"}; List<string> alreadyUsed = new List<string>(); Random r = new Random(); while (alreadyUsed.Count < Names.Length) { int index = r.Next(0, Names.Length); if (!alreadyUsed.Contains(Names[index])) alreadyUsed.Add(Names[index]); Console.WriteLine(...

Random generic tree java

Image
Clash Royale CLAN TAG #URR8PPP Random generic tree java I want to create a tree that has these characteristics. Example scheme All elements (files and directories) must be generated randomly. As input I have to have the depth level and a number of elements to create. what have you tried so far ? – мυѕτавєւмo 20 mins ago By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

JAVA swing. movement from random point to random point

Image
Clash Royale CLAN TAG #URR8PPP JAVA swing. movement from random point to random point i have a problem with one thing. I have a map of 10 cities and a civilian. I want the civilian to be walking from city to city randomly. But the problem is that the city is beeing chosen on and on so the civilian is changing the destination before he reachs it. This is my part of a code of a Jpanel where everything is drawn: @Override public void run() { while (running) { update(); repaint(); try { Thread.sleep(17); } catch (InterruptedException ex) { } } } private void update() { if (game != null && running == true) { c.goTo(cities); // c is civilian } } and this is part of code for civilian private boolean set = true; public void move(int x, int y) { if (this.location.x != x || this.location.y != y) { if (this.location.x > x) { this.location.x -= 1; } else { this.lo...

How to specify the number of odd and even numbers from a random generator in R?

Image
Clash Royale CLAN TAG #URR8PPP How to specify the number of odd and even numbers from a random generator in R? I need to generate a random selection of 9 whole numbers from 1 to 40 with the following condition: the output must contain 5 even numbers and 4 odd numbers. random even odd I have the following code to generate 9 random numbers: x1<- sample(1:40, 9, replace=F) > x1 [1] 2 36 6 10 39 17 14 11 25 I now need to add the odd and even numbers condition in the equation. How can I do this? 2 Answers 2 Assuming the order of the numbers does not matter, you could try c(sample(seq(2,40,by=2), 5, replace=F), sample(seq(1,39,by=2), 4, replace=F)) where seq(2,40,by=2) generates the even numbers, and seq(1,39,by=2) generates the odd numbers. If the order does matter (i.e. it should also be random), you can wrap the outer c with sample : seq(2,40,by=2) seq(1,39,by=2) c sample sample(c(sampl...