numbers

Only allow numeric values in the textbox

ぐ巨炮叔叔 提交于 2019-12-19 06:01:19
问题 I want to make a TextBox control that only accepts numerical values. How can I do this in VB6? 回答1: In the text box text Change event, check if the entered value is a number. If it's not a number then set the old value back again. Dim textval As String Dim numval As String Private Sub TextBox1_Change() textval = TextBox1.Text If IsNumeric(textval) Then numval = textval Else TextBox1.Text = CStr(numval) End If End Sub 回答2: Right click on control box > component > Control -> Microsoft Masked

Generate integer random numbers from range (0:10^12)

本小妞迷上赌 提交于 2019-12-19 05:10:10
问题 I want to generate 10000 integer random numbers between 0 and 10^12. Usually, the code would look like this: x <- sample(0:1000000000000,10000,replace=T) But I get following error message: Error in 0:1000000000000 : result would be too long a vector Is there a more memory efficient method that doesn't have to put 10^12 integers in a vector just to get a sample of size 10000? If not, is there a way to increase the max size of the vector? I'm working on a 64bit OS with 12GB of free RAM. 回答1:

Why is multiplied many times faster than taking the square root?

天大地大妈咪最大 提交于 2019-12-19 04:56:20
问题 I have several questions with the following algorithms to tell if a number is prime, I also know that with the sieve of Eratosthenes can be faster response. Why is faster to compute i i * sqrt (n) times. than sqrt (n) just one time ? Why Math.sqrt() is faster than my sqrt() method ? What is the complexity of these algorithms O (n), O (sqrt (n)), O (n log (n))? public class Main { public static void main(String[] args) { // Case 1 comparing Algorithms long startTime = System.currentTimeMillis(

Generate unique number based on string input in Javascript

南楼画角 提交于 2019-12-19 03:24:38
问题 In the past I have made a function that generates an unique id (number) from a string. Today I discover that it is not as unique as should be. Never saw a problem before with it. Today two different inputs generates the same id (number). I use the same technique in Delphi, C++, PHP and Javascript to generate the same id's so there is no difference when different languages are involved to a project. For example this can be handy to communicate, for HTML id's, tempfiles etc. In general, what I

Non-Uniform Random Number Generator Implementation?

陌路散爱 提交于 2019-12-19 03:17:34
问题 I need a random number generator that picks numbers over a specified range with a programmable mean. For example, I need to pick numbers between 2 and 14 and I need the average of the random numbers to be 5. I use random number generators a lot. Usually I just need a uniform distribution. I don't even know what to call this type of distribution. Thank you for any assistance or insight you can provide. 回答1: You might be able to use a binomial distribution, if you're happy with the shape of

In Bash, how to convert number list into ranges of numbers?

对着背影说爱祢 提交于 2019-12-19 02:42:10
问题 Currently I have a sorted output of numbers from a command: 18,19,62,161,162,163,165 I would like to condense these number lists into a list of single numbers or ranges of numbers 18-19,62,161-163,165 I thought about trying to sort through the array in bash and read the next number to see if it is +1... I have a PHP function that does essentially the same thing, but I'm having trouble transposing it to Bash: foreach ($missing as $key => $tag) { $next = $missing[$key+1]; if (!isset($first)) {

Sublime Text 2 increment numbers

为君一笑 提交于 2019-12-18 21:53:30
问题 I have a JSON file that looks like this: "Algeriet" : [ { "name" : "Nyårsdagen", "date" : "2013-01-01", "ID" : "1" }, { "name" : "Mawlid En Nabaoui Echarif", "date" : "2013-01-24", "ID" : "2" }, { "name" : "Första maj", "date" : "2013-05-01", "ID" : "3" }, ... ] Now I would like to begin incrementing the IDs from 0 instead of 1. How can I do this with Sublime Text 2? I have installed the Text Pastry plugin but I'm not sure how to select the IDs in the text so that I can replace these values.

check NaN number

Deadly 提交于 2019-12-18 18:41:47
问题 Is it possible to check if a number is NaN or not? 回答1: Yes, by use of the fact that a NaN is not equal to any other number, including itself. That makes sense when you think about what NaN means, the fact that you've created a value that isn't really within your power to represent with "normal" floating point values. So, if you create two numbers where you don't know what they are, you can hardly consider them equal. They may be but, given the rather large possibility of numbers that it may

How can you compute a shortest addition chain for an arbitrary n <= 600 within one second?

假装没事ソ 提交于 2019-12-18 17:27:30
问题 How can you compute a shortest addition chain (sac) for an arbitrary n <= 600 within one second? Notes This is the programming competition on codility for this month. Addition chains are numerically very important, since they are the most economical way to compute x^n (by consecutive multiplications). Knuth's Art of Computer Programming, Volume 2, Seminumerical Algorithms has a nice introduction to addition chains and some interesting properties, but I didn't find anything that enabled me to

Display flaw with HTML input type number on iPhone iOS/Safari

妖精的绣舞 提交于 2019-12-18 17:26:07
问题 I want to use HTML input type="number" on a mobile application, in order to indicate to the smarter mobile phones (Android, iPhone and some others), that the numeric keyboard is more interesting for the user than the normal one. This works nicely. So, I have this piece of HTML here: <h3>type="number"</h3> <input type="number" class="input-number"/> <h3>type="text"</h3> <input type="text" class="input-text"/> The important CSS elements applied here are: input { height: 2em; padding: 0.2em 0