Random r = new Random(); int i1 = r.nextInt(max - min + 1) + min;   I've tried it and it is working but still confuse about the logic used, I want to know that why we add min value to random number in end?
How do I generate a random int value in a specific range? I have tried the following, but those do not work: Attempt 1: randomNum = minimum + (int)(Math.random() * maximum);  Bug: randomNum can be bigger than maximum. Attempt 2: Random rn = new Random(); int n = maximum - minimum + 1; int i = rn.nextInt() % n; randomNum =  minimum + i;  Bug: randomNum can be smaller than minimum.
I just got a new hat! :D screaming with joy Looking at so many users looking all exquisite with their stunningly 'fitted' hats, I'm wondering if there's an option to resize or rotate a hat?  PS: Happy Winter Bash everyone! :) Windows utility to render which key I am pressing on-screen How do I perform a Perl substitution on a string while keeping the original? In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?  I usually just copy the string to a new variable then bind it to the s/// regex that does the replacement on the new string, but I was wondering if there is a better way to do this?  $newstring = $oldstring; $newstring =~ s/foo/bar/g; Regular expression: match start or whitespace Can a regular expression match whitespace or the start of a string?  I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.  &gt;&gt;&gt; import re &gt;&gt;&gt; text = u'GBP 5 Off when you spend GBP75.00'  &gt;&gt;&gt; re.sub(ur'GBP([\W\d])', ur'£\g&lt;1&gt;', text) # matches GBP with any prefix u'\xa3 5 Off when you spend \xa375.00'  &gt;&gt;&gt; re.sub(ur'^GBP([\W\d])', ur'£\g&lt;1&gt;', text) # matches at start only u'\xa3 5 Off when you spend GBP75.00'  &gt;&gt;&gt; re.sub(ur'(\W)GBP([\W\d])', ur'\g&lt;1&gt;£\g&lt;2&gt;', text) # matches whitespace prefix only u'GBP 5 Off when you spend \xa375.00'   Can I do both of the latter examples at the same time? JDK 1.4.2 - where can I download the source? I want to install Java JRE 1.4.2 or JDK 1.4.2 on a recent Amazon Linux server. The best option so far seems to install from source. However - where can I download this? I believe 1.4 is still from the Sun era, but I can't find it on the  site, and the sun site is gone.  has no 1.4 download afaik.   Where can I download Java 1.4.2 source code?   As the goal is to get the installation working, other options are welcome. I tried to install the bin file, but got an error: cannot execute binary file. Would a Jedi (Sith) clone be force-full or force-less Just seen a picture of Vader Force-choking a trooper. And then I started wondering: what if they had cloned a Sith (or a Jedi). Would the clones have the Force? Specifically, would they have the same Force as the original? First time using bevel tool, doesn't bevel evenly. What am i doing wrong? Draw power from a portable mobile charger to power circuits I usually power my beginner prototype circuits using mb102 power supply board, but it needs an external elimeter to draw power and then regulate it.  I was looking for a portable solution for my 5 volt and 3.3 volt circuit needs and came up with using a portable battery charger for mobile phones.  I tried powering up a simple transistor and LED circuit with it but it wouldn't power-up.   I feel that there is some load sensing circuit in the portable charger which doesn't detect these low power circuits.  I also tried connecting different resistors to the charger, the charger outputs 5 Volts for a few seconds and then again shuts down and doesn't stay ON continuously.  It would be really comfortable to use a portable charger since it could be charged using a phone charger and would be very handy.  What can I do to make the charger output power on low loads? What are the light blue lines on my imported objects Find all real numbers $x$ for which $$\frac{8^x+27^x}{12^x+18^x}=\frac76$$  I have tried to fiddle with it as follows:   $$2^{3x} \cdot 6 +3^{3x} \cdot 6=12^x \cdot 7+18^x \cdot 7$$ $$ 3 \cdot 2^{3x+1}+ 2 \cdot 3^{3x+1}=7 \cdot 6^x(2^x+3^x)$$ Dividing both sides by $6$ gives us $$2^{3x}+3^{3x}=7 \cdot 6^{x-1}(2^x+3^x)$$  Is this helpful? If so, how should I proceed form here? If not any hints would be greatly appreciated. Why didn’t anyone dial Abydos before Daniel solved the mystery of the seventh symbol? From what I recall from the movie, Daniel only finds the seventh symbol... however when he explain they give way to show him the star gate and they put their sequence in the dialing computer. This proves the dialing computer was prepared to dial 7 chevrons.  It’s also stated they’ve also tested the 6 previous symbols in the order they appear on before, one has to assume only to fail when they insert the 7th, making them aware of the fact you can, at least dial 7th chevrons.  With 39 chevrons on the gate and 6 already locked in, that leaves 33 to try to get a lock. Those are not that many not to go and simply try one by one so... how come nobody brute forced the thing? What causes javac to issue the "uses unchecked or unsafe operations" warning Hat duplicates when info is expanded It seems like there is a bug that is causing a duplicate hat to appear when I expand info, like pressing &quot;(more)&quot; on a suggested edit. This bug does not seem to be specific to the suggested edits review queue though, as others have reported seeing this bug in other places, like code snippet expansion. Steps to repro:  Put on a hat. Navigate to one of your own suggested edits. (You can just also open the Suggested Edits review queue and go to a random suggestion, but there is no guarantee any of those users will be wearing a hat.) Click the &quot;(more)&quot; button to expand the top box.  What should happen: Hat should shift down with the rest of the content. What happens: All the content shifts down, but a duplicate hat remains in the initial place. Before expansion:  After expansion with duplicate hat: Can you attack with different weapons using Extra Attack? The fighter's  feature (PHB, p. 72) says:     Beginning at 5th level, you can attack twice, instead of once, whenever you take the Attack action on your turn.   Assuming I am holding two different weapons, and don't want to spend my bonus action on Two-Weapon Fighting, can I attack once with each weapon? What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried:  import os  file_path = "/my/directory/filename.txt" directory = os.path.dirname(file_path)  try:     os.stat(directory) except:     os.mkdir(directory)         f = file(filename)   Somehow, I missed os.path.exists (thanks kanja, Blair, and Douglas). This is what I have now:  def ensure_dir(file_path):     directory = os.path.dirname(file_path)     if not os.path.exists(directory):         os.makedirs(directory)   Is there a flag for "open", that makes this happen automatically? If I use a program such as SpeedFan to keep my fans at 100% power 24/7, will it harm my computer? I don't care about my power bill but if the excess power could harm my computer I would worry. I have a 350 watt power supply so I don't think the excess power usage will harm it. Here's what I think:  Pros   Things it cools off are kept cooler Cooler parts = faster computer Cooler parts = slower fail rate   Cons   It just sounds wrong. I know this sounds dumb but still Most fans are designed to do their job already I'm either gaming or just browsing the web. Obviously gaming while keeping the fans on can be beneficial but my computer doesn't get very hot while browsing the internet. Custom counter steps twice when invoked from caption using caption package How can I prove the following?  $\gamma (t)$ is unit speed, $\dot \gamma(t) \not= 0 \Rightarrow \ddot \gamma(t)$ is perpendicular to $\gamma(t)$   I don't really see where a problem would arise when $\dot \gamma(t)=0$ would cause such a problem I'm using Ubuntu 17.10 with GNOME shell and Numix-Circle icon theme.   When I hover over the Numix icon for Nightly Web Browser, which is pinned to the dock I get the title "Nightly Web Browser".      But when I launch the program, another icon pops up at the bottom, with the name "Nightly". Use a execute command once