How does Javascript’s Math.random() works behind the scenes? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've always wondered how on earth does Javascript picks a random number and how can it possibly be random? Don’t computers just take in some input, swirl it around with some math, and then return it?
I'm not asking how to generate a random number with Math.random(), my question is: What happens when you want to generate a ‘random’ number? How does that even work and what’s happening behind the scenes? I understand it's a big topic to discuss but any links will be appreciated!

Some random number generator functions use some kind of system noise or entropy (eg: current timestamp) and apply some mathematical function to it to generate random numbers. They are "true" random numbers.
Some functions work by using a seed value and an algorithm to generate numbers that appear to be random, but that is in fact predictable. They are called "Pseudorandom" numbers.
You can read more here: https://www.howtogeek.com/183051/htg-explains-how-computers-generate-random-numbers/

Related

Need some help in understanding JavaScript datatypes [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Why JavaScript need datatypes?
I am trying to understand that what JavaScript will exactly do by knowing the type of data?
What is the benefit of having datatypes in JavaScript?
Based on the type of data, will there be any dynamic memory allocation happens OR there is any size limit like how some languages like C have (example: int : 2 bytes in C)?
All languages must implement some typing system. Javascript is dynamically typed meaning it assumes whatever type you assign to it (ex. var num = 5. Num assumes the type of "number").
By knowing the type of data, javascript will know which operations to perform on that data. For example: 2+2=4, but "2"+"2"=22.
You most likely don't have to worry about having a memory size limit for the number datatype. I don't know about strings, but numbers are infinite in javascript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management for info on memory management.

arranage array from highest to lowest value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I need to arrange an array from highest to lowest in a function
i have used array.sort but was informed that that was not allowed for my exerccise
function minmax(array){
var ar = array.sort().join();//I cant use array.join methood
return ar
}
Please help out
One solution could be to implement any of the popular sorting algorithms, but make the comparison used prioritize larger numbers. One example is this link, the code of which only needs a > flipped to a <.
Note that if this is a homework or school excercise, copying from anywhere is plagiarism and is generally discouraged.

Compare points in two grids [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two raster with x points on it like this:
I have this data from each raster in a array like this:
[
[200,330],
[500,800]
]
How can i compare this data to figure out how many percent as equal this both grids to each other?
My idea is to generate a hash and compare this both hashes, but i don't have an idea how can i do this.
This idea comes from audio fingerprinting.
I will do this in swift or javascript.
Thanks you for each thought!
What you are looking for is to compute the similarity between two vectors.
In your case the vector looks like: [[x1,y1], [x2,y2], ...,[xn, yn]]
I would recommend Cosine Similarity.
The implementation is pretty straight forward, regardless the programming language.
(There are existing implementation of Cosine Similarity out there, for example In JavaScript)

Are there any downsides to using very very very large bit flags (aside from memory) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I realize that bit shifting is handled in 32 bits, but I realized that (at least with modern browsers), I can declare pretty massive numbers - ie:
console.log([
0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF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FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
].join('\n'));
Appear valid and correct. I've tested performance on this, and it seems to be much much faster than any boolean operation, so I'd like to move to this method -- however, I'm a little weary of using huge numbers since I've never seen anything like this before. Do you see or have you run into issues using huge bit flags?
Performance benchmark here: http://jsperf.com/bitwise-v-property-access/3
The numbers in your array are not 'valid and correct'. They overflow the 32 bit boundary, so they are converted to IEE754 64 bit doubles, so they loose precision when too much digits are set.
You cannot use such figures to perform your operations i fear.
Edit : the output of your code is (on latest Chrome/mac OS) :
(as you can see in this fiddle : http://jsbin.com/OQiCAhUk/1/ )
"18446744073709552000
7.922816251426434e+28
3.402823669209385e+38
1.461501637330903e+48
6.277101735386681e+57
2.695994666715064e+67
1.157920892373162e+77
4.9732323640978664e+86
2.13598703592091e+96
9.173994463960286e+105
3.940200619639448e+115
1.6923032801030364e+125
4.542742026847543e+133
1.2194330274671845e+142
3.273390607896142e+150
8.78694100496718e+158
2.3587265155134633e+167
6.331658277711476e+175
1.6996415770136547e+184"
so it seems even the second number is already out of bounds.

JavaScript distributed computing project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I made a website that does absolutely nothing, and I've proven to myself that people like to stay there - I've already logged 11+ hours worth of cumulative time on the page.
My question is whether it would be possible (or practical) to use the website as a distributed computing site.
My first impulse was to find out if there were any JavaScript distributed computing projects already active, so that I could put a piece of code on the page and be done. Unfortunately, all I could find was a big list of websites that thought it might be a cool idea.
I'm thinking that I might want to start with something like integer factorization - in this case, RSA numbers. It would be easy for the server to check if an answer was correct (simply test for modulus equals zero), and also easy to implement.
Is my idea feasible? Is there already a project out there that I can use?
Take a look at http://www.igvita.com/2009/03/03/collaborative-map-reduce-in-the-browser/ and http://www.igvita.com/2009/03/07/collaborative-swarm-computing-notes/

Categories

Resources