I want to print 10 random numbers from -100 to 100, but my code below always print negitive number. I did not get any answer for this. How to do this ?  import java.util.Random; public class VectorAndList { public static void main(String arg[]){     Random random = new Random();     int number ;     for(int i=0;i&lt;10;i++)     System.out.println(number = random.nextInt(100)+ (-100)) ; } }
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.
phpmyadmin not working due to missing extensions I am about to use phpmyadmin on Ubuntu 16.04. But it shows that the page is not working. the error log says error 500   PHP Fatal error:  require_once(): Failed opening required '/usr/share/php/php-gettext/gettext.inc' (include_path='.:/usr/share/php') in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 477   At first it says that the mysqli|mysql extension is missing. but after sleepless hours I forget what I've been done to it. I am using php7. How can I make a single event handler handle ALL Button.Click events? How do you differentiate the likelihood function for the uniform distribution in finding the M.L.E.? There is a classic problem:  Suppose that $X_1,\ldots,X_n$ form an i.i.d. sample from a uniform distribution on the interval $(0,\theta)$, where $\theta&gt;0$ is unknown. I would like to find the MLE of $\theta$.  The pdf of each observation will have the form: $$ f(x\mid\theta) =  \begin{cases} 1/\theta\quad&amp;\text{for }\, 0\leq x\leq \theta\\ 0 &amp;\text{otherwise}. \end{cases} $$ The likelihood function therefore has the form: $$ L(\theta) = \begin{cases} 1/\theta^n \quad&amp;\text{for }\; 0\leq x_i \leq \theta\;\; \text{for all }i,\\ 0 &amp;\text{otherwise}. \end{cases} $$ The general solution is usually that the MLE of theta must be a value of $\theta$ for which $\theta \geq x_i$ and which maximizes $1/\theta^n$ among all such values.   The reasoning is that since $1/\theta^n$ is a decreasing function of $\theta$, the estimate will be the smallest possible value of $\theta$ such that $\theta\geq x_i$.  Therefore, the mle of $\theta$, $\hat{\theta}$, is $\max(X_1,\ldots,X_n)$.  Here, I do not understand why we cannot just differentiate the likelihood function with respect to theta and then set it equal to $0$?  Thanks! Installation problem QGIS I do not manage to install QGIS on my windows 10 machine using the osgeo4w installer.  During the installation I get this message:   At the end of the installation I get this message:   And when I subsequently try to run QGIS, I receive this message:    Similar issue can be found in various fora, but none of them provides a conluding answer or did help me to solve the problem.  Any propositions? Can a probability distribution value exceeding 1 be OK? On the , there is this line:      $p(\mathrm{height}|\mathrm{male}) = 1.5789$ (A probability distribution over 1 is OK. It is the area under the bell curve that is equal to 1.)    How can a value $&gt;1$ be OK? I thought all probability values were expressed in the range $0 \leq p \leq 1$. Furthermore, given that it is possible to have such a value, how is that value obtained in the example shown on the page? Finding the missing digits of $23!$ It is given $23!=2585201xy38884976640000$. Now it is required to find the value of $x$ and $y$. I know I could find it by using divisibility rules and solving simultaneous equations. Is there any other way to solve it (without computing it by a calculator)? This question is just out of curiosity. Can I just change straightforward wheel axles to QR skewers? How to use the keyboard to drag and drop? Switch statement fall-through...should it be allowed? How does JavaScript .prototype work? I'm not that into dynamic programming languages but I've written my fair share of JavaScript code. I never really got my head around this prototype-based programming, does any one know how this works? var obj = new Object(); obj.prototype.test = function() { alert('Hello?'); }; var obj2 = new obj(); obj2.test();  I remember a lot discussion I had with people a while back (I'm not exactly sure what I'm doing) but as I understand it, there's no concept of a class. It's just an object, and instances of those objects are clones of the original, right? But what is the exact purpose of this &quot;.prototype&quot; property in JavaScript? How does it relate to instantiating objects? Update: correct way var obj = new Object(); // not a functional object obj.prototype.test = function() { alert('Hello?'); }; // this is wrong!  function MyObject() {} // a first class functional object MyObject.prototype.test = function() { alert('OK'); } // OK  Also these  really helped a lot. What is the difference between re.search and re.match? How to disk copy with unreadable sectors? I want to clone a whole disk bytewise, something like  dd if=/dev/$SRC of=/dev/$DST bs=65536 count=$count   There are better tools for the job, which understand the file system (Windows) and work faster (I don't care), but they fail because of unreadable sectors on the old source disk.  There's actually a single invalid block I have to skip. So I thought about using dd multiple times like  dd if=/dev/$SRC of=/dev/$DST bs=65536 count=... dd if=/dev/zero of=/dev/$DST bs=65536 count=... skip=... seek=... dd if=/dev/$SRC of=/dev/$DST bs=65536 count=... skip=... seek=...   with replacing the broken sector data by zeros. Is this a valid approach? I found this  which confuses me. New phone: How to transfer game progress? I'm planning to buy a new Android phone and I'd like to be able to transfer the progress I have made at several games to the new device, so I won't have to play all the levels again from scratch.  I currently have an HTC Desire and will buy an HTC Evo 3D.  There's probably no simple/general solution to this.  But I was wondering if anyone did something similar and could provide some advice (e.g. where to look for files that might hold game progress information). What does high credit utilization really mean? Best practices with STDIN in Ruby? I want to deal with the command line input in Ruby:  &gt; cat input.txt | myprog.rb &gt; myprog.rb &lt; input.txt &gt; myprog.rb arg1 arg2 arg3 ...   What is the best way to do it? In particular I want to deal with blank STDIN, and I hope for an elegant solution.  #!/usr/bin/env ruby  STDIN.read.split("\n").each do |a|    puts a end  ARGV.each do |b|     puts b end How to fix a stripped pedal crank The threads on my bike's pedal crank just became fully stripped and the pedal fell off, though the pedal itself is fine. Is there any way I can fix this without fully replacing the pedal crank? When is it better to use String.Format vs string concatenation? To prove Cayley-Hamilton theorem, why can't we substitute $A$ for $\lambda$ in $p(\lambda) = \det(\lambda I - A)$? I edit a lot of posts every day. I often run across posts with 'Hi' and 'Thanks' on the top and the bottom of the post respectively. I also run across things like:     --User   Should these items be removed during the editing of the post by an editor? Select Command not working while run shell scripts on remote machine