numbers

Get a random number focused on center

蹲街弑〆低调 提交于 2019-11-29 18:34:28
Is it possible to get a random number between 1-100 and keep the results mainly within the 40-60 range? I mean, it will go out of that range rarely, but I want it to be mainly within that range... Is it possible with JavaScript/jQuery? Right now I'm just using the basic Math.random() * 100 + 1 . The simplest way would be to generate two random numbers from 0-50 and add them together. This gives a distribution biased towards 50, in the same way rolling two dice biases towards 7. In fact, by using a larger number of "dice" (as @Falco suggests) , you can make a closer approximation to a bell

Decimal Pipe in Angular 2 - Commas Only, No Decimal Places

情到浓时终转凉″ 提交于 2019-11-29 18:20:59
问题 I currently use this pipe {{ product.productPrice | number:'.2-2' }} And result is 1,000,000.00 but I want to remove the .00 How do you do that? 回答1: Use this : {{product.productPrice | number: '1.0-0'}} 1.0-0 means: at least one digit before decimal point, 0 digits after decimal point. https://angular.io/api/common/DecimalPipe 来源: https://stackoverflow.com/questions/45955101/decimal-pipe-in-angular-2-commas-only-no-decimal-places

How to generate a random number from 1 to 100 only once?

半世苍凉 提交于 2019-11-29 18:15:33
I need to generate a random number from 1 to 100 in AS3 that will not be generated twice. So I need every number be generated until all the numbers are complete. How can I do that? Fill an array with the numbers 1 to 100. Randomly shuffle it (use Fisher-Yates shuffle). Take each number starting from the first array index onwards... Fill an Array '_randomNumbers' with the numbers 1-100. Each time you need a number use the following: if (_randomNumbers.length>0) { newRandomNumber = _randomNumbers.splice( Math.floor(Math.random(_randomNumbers.length)), 1 )[0]; } Shakeeb Ayaz check out this for

How to set DocumentFilter with input length and range? e.g. 1-3 or 10-80

大城市里の小女人 提交于 2019-11-29 18:06:53
I'm using DocumentFilter to restrict input as integer or decimal. And the code I post here is working well for that. Can anybody help me about how to restrict the input length or range in the given code? Thanks!! class MyIntFilter extends DocumentFilter { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.insert(offset, string); if (test(sb.toString())) { super.insertString(fb, offset, string, attr); } else {

drawing random number from a standard normal distribution using the standard rand() functions

无人久伴 提交于 2019-11-29 18:05:46
So most programming languages contain a rand() functionality whereby you can generate a random number between 0 to 1.... My question is, is there a way to manipulate this standard rand() functionality such that you are able to instead draw a random number from normal distribution with a mean and standard deviation? Notice that I'm not asking whether or not a language has a normal distribution functionality built in, I'm asking if you can "simulate" drawing a normal distribution random variable using a rand() function... Here is a simple way that works (from here ): static Random r = new Random

Make Random Numbers Tend / Average to a Specific Value

那年仲夏 提交于 2019-11-29 17:45:49
How can I for example generate a list of random numbers between 0 and 1, but have them avarage at 0.8? I have written this little script in C++ that'll tell you what numbers got output. This question is not really C++ related though. #include <iostream> #include <random> #include <time.h> int main(int argCount, char** argVector) { std::cout << "Generating Randoms" << std::endl; float avarage = 0.F; srand(rand() + (int) time(NULL)); float ceiling = 0; float bottom = 1; for(unsigned int i = 0; i < 1000000; i++) { float random = (float) (rand() % 101) / 100; if(random > ceiling) ceiling = random;

Generating a sequence using prime numbers 2, 3, and 5 only, and then displaying an nth term (C++)

爱⌒轻易说出口 提交于 2019-11-29 17:41:11
I'm working on a problem that asks to generate a sequence using prime numbers 2, 3, and 5, and then displaying then nth number in the sequence. So, if I ask the program to display the 1000th number, it should display it. I can't be using arrays or anything like that, just basic decisions and loops. I started working on it and hit a wall... here's what I got: #include <iostream> using namespace std; int main() { unsigned int n=23; for(int i=2; i<n; i++){ if(i%2==0){ cout<<i<<", "; }else if(i%3==0){ cout<<i<<", "; }else if(i%5==0){ cout<<i<<", "; } } return 0; } Unfortunately, that code doesn't

c/c++ notation of double floating point values

こ雲淡風輕ζ 提交于 2019-11-29 17:21:28
What's the notation for double precision floating point values in C/C++? .5 is representing a double or a float value? I'm pretty sure 2.0f is parsed as a float and 2.0 as a double but what about .5? http://c.comsci.us/etymology/literals.html Tomek It's double. Suffix it with f to get float. And here is the link to reference document: http://en.cppreference.com/w/cpp/language/floating_literal Technically, initializing a float with a double constant can lead to a different result (i.e. cumulate 2 round off errors) than initializing with a float constant. Here is an example: #include <stdio.h>

Print largest number in a 2d array - why do my code print three numbers

陌路散爱 提交于 2019-11-29 16:45:24
I am trying to print out the largest number in a 2D array. My problem is that my output are three numbers instead of one - the largest. Why? Here is my code: public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { int maxRows = 3; int maxCols = 4; int [] onedArray = new int [maxRows]; for (int i = 0; i < maxRows; i++){ onedArray[i] = (int) ((Math.random() * 100) * maxCols); } int [][] twodArray = new int[maxRows][]; for (int i = 0; i < maxRows; i++){ twodArray[i] = new int[maxCols]; } for (int i = 0; i < twodArray.length; i++){ for (int j =

PHP - Get length of digits in a number

跟風遠走 提交于 2019-11-29 16:34:06
问题 I would like to ask how I can get the length of digits in an Integer. For example: $num = 245354; $numlength = mb_strlen($num); $numlength should be 6 in this example. Somehow I can't manage it to work? Thanks EDIT: The example code above --^ and its respective method mb_strlen(); works just fine. 回答1: Maybe: $num = 245354; $numlength = strlen((string)$num); 回答2: Accepted answer won't work with the big numbers. The better way to calculate the length of any number is to invoke floor(log10($num