numbers

Random number bigger than 100,000

冷暖自知 提交于 2019-12-07 07:38:41
问题 I'm writing in C/C++ and I want to create a lot of random numbers which are bigger than 100,000. How I would do that? With rand(); 回答1: // Initialize rand()'s sequence. A typical seed value is the return value of time() srand(someSeedValue); //... long range = 150000; // 100000 + range is the maximum value you allow long number = 100000 + (rand() * range) / RAND_MAX; You may need to use something larger than a long int for range and number if (100000 + range) will exceed its max value. 回答2:

A function where small changes in input always result in large changes in output

余生颓废 提交于 2019-12-07 06:19:40
问题 I would like an algorithm for a function that takes n integers and returns one integer. For small changes in the input, the resulting integer should vary greatly. Even though I've taken a number of courses in math, I have not used that knowledge very much and now I need some help... An important property of this function should be that if it is used with coordinate pairs as input and the result is plotted (as a grayscale value for example) on an image, any repeating patterns should only be

JavaScript factorial prevent infinity

荒凉一梦 提交于 2019-12-07 06:17:59
问题 I have been using this function for calculating factorial numbers in JavaScript: var f = []; function factorial (n) { if (n == 0 || n == 1) return 1; if (f[n] > 0) return f[n]; return f[n] = factorial(n-1) * n; } All seemed to be going well until I tried the number 500 . It returned infinity . Is there a way that I can prevent infinity as an answer? Thank you. 回答1: You indeed need to use bignumbers. With math.js you can do: // configure math.js to work with enough precision to do our

Number of Records in Insert Statement (Oracle)

本秂侑毒 提交于 2019-12-07 05:56:52
问题 I'd like to report on the number of records inserted in an Oracle insert statement. I'm inserting from a statement, so I could run my select twice and a count, but I'd rather keep it all in a single statement. Is there a way? 回答1: Doing an INSERT in PL/SQL SQL%ROWCOUNT gives the number of inserted rows. Doing an INSERT in C# cmd.ExecuteNonQuery() returns the number of inserted rows. 来源: https://stackoverflow.com/questions/1468396/number-of-records-in-insert-statement-oracle

Toad truncating/rounding large Oracle numbers?

不羁岁月 提交于 2019-12-07 03:29:16
问题 We have a table with a 'price' field of type NUMBER(20,7) .. In TOAD I do this: update mytable set price = 1234567890123.1234567; Then I do this select: select price, to_char(price) from mytable PRICE TO_CHAR(PRICE) 1234567890123.12 "1234567890123.1234567" Question is, why does TOAD truncate the result when displaying the NUMBER(20,7) field? The data is obviously there as it prints out with to_char. ?? 回答1: Toad limits numbers in the data grid to 15 digits. I believe this is because excel

C++ How to output number with at least one number behind the decimal mark

蓝咒 提交于 2019-12-07 03:08:09
问题 How can I make my program output a number with at least one number behind the decimal mark C++? Output: 1 = 1.0 or 1.25 = 1.25 or 2.2 = 2.2 or 3.456789 = 3.456789 Thanks in advance 回答1: Use showpoint to force the decimal point to be printed double x = 1.0; std::cout << std::showpoint << x << "\n"; It will be followed by the number of 0 required to satisfy the precision of the stream. 回答2: #include <cmath> #include <iostream> #include <limits> struct FormatFloat { static constexpr const double

R - how to re-order data frame by row index number

泄露秘密 提交于 2019-12-07 01:42:34
问题 This may be a very basic question but I could't find it. Let's say I have a data frame d with row numbers in disorder like this: Signal 4 9998 3 549 1 18 5 2.342 2 0.043 How can I sort this by increasing row index numbers to obtain the following? Signal 1 18 2 0.043 3 549 4 9998 5 2.342 回答1: d <- read.table(text=readClipboard(), header=TRUE) d$index <- as.numeric(row.names(d)) d[order(d$index), ] 回答2: you can also use this : d[order(as.numeric(rownames(d))),,drop=FALSE] drop is useful only if

Need help generating discrete random numbers from distribution

[亡魂溺海] 提交于 2019-12-06 23:36:43
问题 I searched the site but did not find exactly what I was looking for... I wanted to generate a discrete random number from normal distribution. For example, if I have a range from a minimum of 4 and a maximum of 10 and an average of 7. What code or function call ( Objective C preferred ) would I need to return a number in that range. Naturally, due to normal distribution more numbers returned would center round the average of 7. As a second example, can the bell curve/distribution be skewed

How can I use C# to sort values numerically?

会有一股神秘感。 提交于 2019-12-06 20:02:53
问题 I have a string that contains numbers separated by periods. When I sort it appears like this since it is a string: (ascii char order) 3.9.5.2.1.1 3.9.5.2.1.10 3.9.5.2.1.11 3.9.5.2.1.12 3.9.5.2.1.2 3.9.5.2.1.3 3.9.5.2.1.4 etc. I want it to sort like this: (in numeric order) 3.9.5.2.1.1 3.9.5.2.1.2 3.9.5.2.1.3 ... 3.9.5.2.1.9 3.9.5.2.1.10 3.9.5.2.1.11 3.9.5.2.1.12 I know that I can: Use the Split function to get the individual numbers Put the values into an object Sort the object I prefer to

Fastest way to convert a integer to arbitrarily ordered byte arrays in JavaScript?

霸气de小男生 提交于 2019-12-06 19:44:37
问题 I'm looking to convert the MIN_SAFE_INTEGER through MAX_SAFE_INTEGER range of a JavaScript number (53-bits not including the sign) into a string of bits spread over 7 bytes shifted two to allow for sign and null identifiers. Thus far the best I've come up with is: function toUint8Array(data) { data = data.toString(2); data = new Array(65 - data.length).join('0') + data; var ret = new Uint8Array(data.length / 8); for (var i = 0; i < 8; i++) { ret[i] = 0; ret[i] += (data[i * 8] == '1' ? 128 : 0