Generate 4-digit number without random class I am trying to generate a random 4-digit number using the Java Math.random method. The number must always be 4 digits, i.e., allow for results such as 0001, or 0023, or 0123 to be possible. However, the traditional Math.random method formula below only allows numbers less than 1000 to be 1, 23, or 123.   int i = (int)(Math.random()*10000);    Is there a way to do this using math.random and/or loops? Thank you, in advance, for any suggestions.   I tried researching how to ensure the 4-digit number always has 4 digits, but all results seem to suggest using Random class, or min/max.  I DO NOT want to use this random class or max/min code as I have not yet studied it yet.
How can I pad an integer with zeros on the left? How do you left pad an int with zeros when converting to a String in java?  I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).
I'm just trying to review basic terminal commands. Having said that, how do I create a text file using the terminal only? I am using a logit model. My dependent variable is binary. However I have an independent variable which is categorical and contains the responses: 1.very good, 2.good, 3.average, 4.poor and 5.very poor. So, it is ordinal ("quantitative categorical"). I am not sure how to handle this in the model. I am using gretl.  [Note from @ttnphns: Although the question says the model is logit (because the dependent is categorical), the crucial issue - ordinal independent variables - is basically alike, be the dependent categorical or quantitative. Therefore the question is equally relevant to, say, linear regression too - as it is to logistic regression or other logit model.] How to create live autofill search? I am currently trying to create a wordpress search function that shows live results underneath the search bar. There is an example on the  website (screens below). I'm not looking for an autofill like you would find on Google.com which completes words you type, rather I want it to find actual posts on the site.   I tried doing a scrub through Wordpress Answers and other similar resources but have only run into implementing a Google type search which is not what I am looking for. Any help or points in the right direction would be greatly appreciated. Cryptoclass Throws Error. Invalid private key. Must be 16 bytes. Sending 16 characters long key key__c :- abcdefghijklmnop  public static String decrypt(String data) {     EncryptionSettings__c settings = EncryptionSettings__c.getOrgDefaults();     if (settings.key__c == null) {         throw new FacebookException('Cannot decrypt without a key!');     }     Blob key = EncodingUtil.base64Decode(settings.key__c);     return Crypto.decryptWithManagedIV('AES128', key, EncodingUtil.base64Decode(data)).toString(); }  public static String encrypt(String data) {         EncryptionSettings__c settings = EncryptionSettings__c.getOrgDefaults();     Blob key = null;     if (settings.key__c == null) {         checkUserCanCustomizeApplication();         key = Crypto.generateAesKey(128);         settings.key__c = EncodingUtil.base64Encode(key);         insert settings;     } else {         key = EncodingUtil.base64Decode(settings.key__c);     }     return EncodingUtil.base64Encode(Crypto.encryptWithManagedIV('AES128', key, Blob.valueOf(data))); } How to programmatically create a WPF window in a WinForm application Why is the inclusion of the tensor product of the duals into the dual of the tensor product not an isomorphism? Let $V$ and $W$ be vector spaces (say over the reals). There is a linear injection $V^* \otimes W^* \to (V \otimes W)^*$ which sends $\sum_i f_i \otimes g_i \in V^* \otimes W^*$ to the unique functional in $(V \otimes W)^*$ sending $v \otimes w \mapsto \sum_i f_i(v) \cdot g_i(w)$ for all $(v,w) \in V \times W$. In the finite dimensional case it is easy to see this is an isomorphism by comparing dimensions on both sides. I'm aware that this is not an isomorphism in the infinite-dimensional case (see Relation with the dual space in the  on tensor products) but I must admit that I'm not sure why. Cardinal arithmetic does not seem help here and, even if it did, I would be much happier to see an explicit example of a functional in $(V \otimes W)^*$ outside the range of this map. I'm having trouble cooking one up myself.  Added: Let me elaborate on my comment about cardinal arithmetic. Suppose that $X$ and $Y$ are infinite dimensional vector spaces over a field $k$. I'm confident that $\dim (X \otimes Y) = \dim X \cdot \dim Y$ holds. It is clear that $|X^*| = |k|^{\dim X}$ since we may identify a functional on $X$ with a function from a basis for $X$ to $k$. Also I think I've convinced myself that if $\dim X \geq |k|$ then in fact $|X| = \dim X$ ie. the cardinality and dimension of a vector space agree when the dimension is larger than the cardinality of the ground field. Consequently, assuming say that $|k| \leq \dim X \leq \dim Y$ it seems we have $$ \dim(X \otimes Y)^* = |k|^{ \dim X \cdot \dim Y} = |k|^{ \dim Y} = \dim Y^* = \dim X^* \cdot \dim Y^* = \dim (X^* \otimes Y^*)$$  which implies that in fact $(X \otimes Y)^*$ and $X^* \otimes Y^*$ are isomorphic but, rather frustratingly, the obvious map does not do the job. Did I make a mistake here? If not, is it generally true (ie without making assumptions about $|k|$) that there exists some isomorphism $(X \otimes Y)^* \to X^* \otimes Y^*$? Plotting complex numbers as an Argand Diagram Page title with substitution on views page I have a view page that requires a dynamic page title. It is a simple substitution of the label field.  If I use {{ label }} it works fine for the title displayed on the page, but it doesn't substitute the label for the actual page title (in meta)  I was able to fix this by using hook_views_post_render using the following code  // Set the route title. $route = \Drupal::routeMatch()-&gt;getCurrentRouteMatch()-&gt;getRouteObject(); $route-&gt;setDefault('_title', $title);  $view-&gt;setTitle($title);   However, the title only works if the page is not cached. For the cached pages, the page title is missing. This feels like a bug in drupal, but I am hoping that there is a simple way to get this done. Run VirtualBox in background, without a window? I was wondering if it's possible to run an Ubuntu virtual machine using VirtualBox in background, I mean, without any window open.  The idea is to connect via SSH to the Linux host, that would be running in background.  Has anyone ever done something like this? Is it possible? How do you add a certificate authority (CA) to Ubuntu? This is a question about American English usage of the word "already". As a UK resident I don't completely understand when I hear Americans give commands like "Stop it already!" In the UK the word already is not normally used in the imperative mood and the sentence I've just quoted would leave an English person thinking "If you're saying I've already stopped it why are you asking me to stop it again?" I have a query pattern that must be very common, but I don't know how to write an efficient query for it.  I want to look up the rows of a table that correspond to "the most recent date not after" the rows of another table.  I have a table, inventory say, which represents the inventory I hold on a certain day.  date       | good | quantity ------------------------------ 2013-08-09 | egg  | 5 2013-08-09 | pear | 7 2013-08-02 | egg  | 1 2013-08-02 | pear | 2   and a table, "price" say, which holds the price of a good on a given day  date       | good | price -------------------------- 2013-08-07 | egg  | 120 2013-08-06 | pear | 200 2013-08-01 | egg  | 110 2013-07-30 | pear | 220   How can I efficiently get the "most recent" price for each row of the inventory table, i.e.  date       | pricing date | good | quantity | price ---------------------------------------------------- 2013-08-09 | 2013-08-07   | egg  | 5        | 120 2013-08-09 | 2013-08-06   | pear | 7        | 200 2013-08-02 | 2013-08-01   | egg  | 1        | 110 2013-08-02 | 2013-07-30   | pear | 2        | 220   I know one way of doing this:  select inventory.date, max(price.date) as pricing_date, good from inventory, price where inventory.date &gt;= price.date and inventory.good = price.good group by inventory.date, good   and then join this query again to inventory. For large tables even doing the first query (without joining again to inventory) is very slow.  However, the same problem is quickly solved if I simply use my programming language to issue one max(price.date) ... where price.date &lt;= date_of_interest ... order by price.date desc limit 1 query for each date_of_interest from the inventory table, so I know there is no computational impediment.  I would, however, prefer to solve the whole problem with a single SQL query, because it would allow me to do further SQL processing on the result of the query.  Is there a standard way to do this efficiently? It feels like it must come up often and that there should be a way to write a fast query for it.  I'm using Postgres, but an SQL-generic answer would be appreciated. "Please do not repeat the mistake" and "Please do not repeat the mistake again" I have recently installed lubuntu 11.10 on my old laptop (acer aspire 5315 celeron) and observed that fan is not working properly on lubuntu side.I find it strange that it is working perfectly under window vista.   How could I solve this problem? Can I fly back to Italy if my Italian residency card has expired and is being renewed? I have a residence permit (permesso di soggiorno) for Italy. I am currently in the Netherlands for an exchange. My permit expired on the 30th of November and I applied for a new one but I will get the card in January. I have the documents supporting that I have applied for the renewal of the permit. In the middle I want to travel to Italy for Christmas and come back to the Netherlands.    Would this be a problem? I have seen this many times, a question is being asked because a previous, duplicate question was asked and answered a few years ago and has no longer relevant answers.  The  is to edit the old question, or add new answers to it, but it is not always happening.  I was wondering, should I still mark it as duplicate and vote to close it? Or just leave it as is? Can't install rtl8192eu-linux-driver on UBUNTU 18.10 Should I write "X and I", "X and me", "I and X", or "me and X" in a conjoined object? I know that if you held an infrared remote in front of a digital camera, it'll flash a blue/purplish light when you press the buttons. Why?    (Image by  .) The definition of derivative of a function $f(x)$ is $$\lim_{h\to0} \frac{f(x+h)-f(x)}{h}$$  Using this definition, the derivative of $\sin\sqrt{x}$ will be:  $$\lim_{h\to0} \frac{\sin\sqrt{x+h}-\sin\sqrt{x}}{h}$$  $$\lim_{h\to 0} \frac{\cos\left(\frac{\sqrt{x+h}+\sqrt{x}}{2}\right)\sin\left(\frac{\sqrt{x+h}-\sqrt{x}}{2}\right)}{h}$$  Now i got stuck. How to find the limit or simplify this expression?  I get intuition that we have to use $$\lim_{x\to0}\frac{\sin x}{x} = 1$$  but that too is leading no where. I am unable to remove h from denominator.  NOTE  I know the derivative of $\sin\sqrt{x}$ is $\frac{\cos\sqrt{x}}{2\sqrt{x}}$ using chain rule, but this exercise was given to us for practice using division quotient.