numbers

Best algorithm for hashing number values?

烂漫一生 提交于 2019-12-03 05:15:45
问题 When dealing with a series of numbers, and wanting to use hash results for security reasons, what would be the best way to generate a hash value from a given series of digits? Examples of input would be credit card numbers, or bank account numbers. Preferred output would be a single unsigned integer to assist in matching purposes. My feeling is that most of the string implementations appear to have low entropy when run against such a short range of characters and because of that, the

Random number between negative and positive value [duplicate]

只谈情不闲聊 提交于 2019-12-03 05:14:16
This question already has answers here : Generating random whole numbers in JavaScript in a specific range? (32 answers) Possible Duplicate: Generating random numbers in Javascript in a specific range? How can i get a random value between, for example, from -99 to 99, excluding 0? var num = Math.floor(Math.random()*99) + 1; // this will get a number between 1 and 99; num *= Math.floor(Math.random()*2) == 1 ? 1 : -1; // this will add minus sign in 50% of cases This returns what you want function getNonZeroRandomNumber(){ var random = Math.floor(Math.random()*199) - 99; if(random==0) return

Fastest way to separate the digits of an int into an array in .NET?

↘锁芯ラ 提交于 2019-12-03 05:13:43
问题 I want to separate the digits of an integer, say 12345, into an array of bytes {1,2,3,4,5}, but I want the most performance effective way to do that, because my program does that millions of times. Any suggestions? Thanks. 回答1: How about: public static int[] ConvertToArrayOfDigits(int value) { int size = DetermineDigitCount(value); int[] digits = new int[size]; for (int index = size - 1; index >= 0; index--) { digits[index] = value % 10; value = value / 10; } return digits; } private static

Determine if a String is a number and convert in Java?

纵然是瞬间 提交于 2019-12-03 05:08:47
问题 I know variants of this question have been asked frequently before (see here and here for instance), but this is not an exact duplicate of those. I would like to check if a String is a number, and if so I would like to store it as a double . There are several ways to do this, but all of them seem inappropriate for my purposes. One solution would be to use Double.parseDouble(s) or similarly new BigDecimal(s) . However, those solutions don't work if there are commas present (so "1,234" would

Return row number(s) for a particular value in a column in a dataframe

蹲街弑〆低调 提交于 2019-12-03 04:58:01
问题 I have a data frame (df) and I was wondering how to return the row number(s) for a particular value (2585) in the 4th column (height_chad1) of the same data frame? I've tried: row(mydata_2$height_chad1, 2585) and I get the following error: Error in factor(.Internal(row(dim(x))), labels = labs) : a matrix-like object is required as argument to 'row' Is there an equivalent line of code that works for data frames instead of matrix-like objects? Any help would be appreciated. 回答1: Use which

javascript onclick increment number

我与影子孤独终老i 提交于 2019-12-03 04:38:32
问题 With javascript, how can I do it so when i click a form button it adds 1 to a number? The number it increments could be in a form text field or something. Obviously it'd be on onclick but I'm not sure of the code. 回答1: Since you gave me nothing to start on, here is a simple example. jsFiddle Example implementation: function incrementValue() { var value = parseInt(document.getElementById('number').value, 10); value = isNaN(value) ? 0 : value; value++; document.getElementById('number').value =

Changing the sign of a number in PHP?

為{幸葍}努か 提交于 2019-12-03 04:02:32
问题 I have a few floats: -4.50 +6.25 -8.00 -1.75 How can I change all these to negative floats so they become: -4.50 -6.25 -8.00 -1.75 Also I need a way to do the reverse If the float is a negative, make it a positive. 回答1: A trivial $num = $num <= 0 ? $num : -$num ; or, the better solution, IMHO: $num = -1 * abs($num) As @VegardLarsen has posted, the explicit multiplication can be avoided for shortness but I prefer readability over shortness I suggest to avoid if/else (or equivalent ternary

How to generate unique order number?

无人久伴 提交于 2019-12-03 03:13:10
I'm looking for a good way to generate a unique order ID. Can you see any problems with the code below? int customerId = 10000000; long ticks = DateTime.UtcNow.Ticks; long orderId = customerId + ticks; int orderNumber = orderId.GetHashCode(); I'm going to check that the number is unique in the database before creating the order. If you are storing your records in a database, you should really look into the capabilities available there to generate unique surrogate keys. In SQLServer this would be an IDENTITY field and in Oracle it would be a field that uses a SEQUENCE to generate a new value.

How can I suppress the line numbers output using R CMD BATCH?

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: If I have an R script: print ( "hi" ) commandArgs () And I run it using: r CMD BATCH -- slave -- no - timing test . r output . txt The output will contain: [ 1 ] "hi" [ 1 ] "/Library/Frameworks/R.framework/Resources/bin/exec/x86_64/R" [ 2 ] "-f" [ 3 ] "test.r" [ 4 ] "--restore" [ 5 ] "--save" [ 6 ] "--no-readline" [ 7 ] "--slave" How can i suppress the line numbers[1]..[7] in the output so only the output of the script appears? 回答1: Yes, mbq is right -- use Rscript , or, if it floats your boat, littler : $ cat / tmp / tommy . r #!

Subscript of a struct doesn&#039;t set values when created as an implicitly unwrapped optional

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why can't I change the the "numbers" array using subscripts when "Foo" is an implicitly unwrapped optional? struct Foo { var numbers = [0,0,0] subscript(index: Int) -> Int { get { return self.numbers[index] } set { self.numbers[index] = newValue } } } var fooA:Foo! fooA = Foo() fooA[1] = 1 // does not change numbers array fooA[1] // returns 0 fooA.numbers[1] = 1 // this works fooA[1] // returns 1 var fooB:Foo! fooB = Foo() fooB![1] = 1 // this works fooB![1] // returns 1 For some reason it works when I make "Foo" a class (called "Goo" below)