|
I thought browsers were supposed to fire the mouse events as well as the touch events for single-finger activation gestures?
Touch Events - Level 2[^]
Even Amazon's own documentation say they do:
Touch - Amazon Silk[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Interesting. That's what I had expected too.
But, until I added the explicit touchstart event I was getting nothing. I even tested it with a simple alert(). And, once I added it, it started working. So documentation may say something, but we all know the _real documentation_ is the code.
Thanks for finding those though because i couldn't find those docs. I will read them more closely.
|
|
|
|
|
Closing the loop on this...
That second link explains that the onclick event should fire and it is correct.
I created another barebones HTML page and added a button with an onclick event and tried it from my Amazon Kindle fire pad (running Silk browser) and it worked with no problem.
Hmmm...maybe I had a syntax error on my original HTML and it pre-cluded the touch event from firing properly while a normal desktop browser handled it??
Well, thanks again for your help.
|
|
|
|
|
The "inconsistency" of what events are supported in the HTML vs. events that can only be wired up with addEventListener is basically why I always use addEventListener. Besides the fact that I rather despise the whole "on[event]="someFunctionCall()" in the HTML. Makes it a PITA to figure out where to change the handler, and I also use a "UI event router" for these things so they can be handled by actual object instances, logged, etc.
Yes yes, I know, you're doing a fun web app.
|
|
|
|
|
Marc Clifton wrote: basically why I always use addEventListener. Besides the fact that I rather despise the whole "on[event]="someFunctionCall()" in the HTML.
I like that you made those points. I will keep that in mind.
Yours is a much better Separation of Concerns anyways. I believe the lesson I've just learned (new convention for me) is that it is better to wire up events in the JS itself due to your point and the point that mine didn't work very well.
Thanks again.
|
|
|
|
|
EDIT - NOTE: someone pointed out that I said 5.51 billion but I actually generated 551 Billion random numbers.
Yesterday, I was thinking about the JavaScript Math.random() function.
The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range
I had a script that I uses Math.random() to generate values in range of 1 - 10 (inclusive).
I basically ignored the fact that you could ever get zero. Then something happened and I started wondering why I never seemed to hit the 0 value.
Generate As Many Random Values As Possible
So I decided to write a script and let it just generate random values and run a long while to see if I'd ever actually get 0.
I let the following script run (via NodeJS) for something like 5 or 6 hours and it never generated a value of 0. I finally just killed the script.
var counter = 1;
var MaxLoops = Number.MAX_VALUE;
function runForZero(){
console.log("running...");
for (var x=1;x<=MaxLoops;x++)
{
var rnd = Math.random();
if (rnd === 0)
{
console.log("rnd is " + rnd + " It took " + counter + " tries.");
return;
}
if (counter % 5000000 == 0){
console.log(new Date().toTimeString() + " - Still running : " + counter);
}
counter++;
}
console.log("Complete.");
}
After Reading a Few Thoughts, I Understand, but....
I read this javascript - Can Math.random() exactly equal .5 - Stack Overflow[^] which really exposes the idea that probabilistically (is that a real word? ) you will never hit a specific value.
That SO will also lead you to other readings like : How does JavaScript’s Math.random() generate random numbers? | Hacker Noon[^]
Since 0 is a specific value, it is unlikely that you will ever see that value.
Here's The Thought I Had To Get To For Understanding
Basically think about if you stuck your hand into a bin of numbers which contained from 0 to 1.7976931348623157e+308 (largest Number in JavaScript)*. How likely would it be that you get 0? Or, how many times would you have to stick your hand into the bin to randomly grab the 0? Lots.
But, at some point you must see that value, but you may wait a long time (hundreds of years or something?)
Or it could happen with the first Math.random() call you make.
I think this is an interesting thought experiment, because it will make you think.
*It is some number similar to this for the number of decimal values 0 <= N < 1 (dependent upon Number data type size and precision).
modified 19-Apr-20 21:51pm.
|
|
|
|
|
Quick thumbnail calculation:
Most optimistic (for this purpose) and very likely case, the PRNG returns one of 2^52 values. It might be more, but that's how many bits are in the mantissa of a JS Number.
2^52 is about 4.5e15. You tried 5.5e9 5.5e11 samples, so your chance of hitting any specific value is on the order of 1e-6 1e-4.
Your observation still is entirely plausible.
If you ran it for, say, 3 years you'd be getting on for likely to hit zero.(P ~ 0.5)
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
modified 19-Apr-20 22:41pm.
|
|
|
|
|
You have a slight disagreement with yourself. 551,855,000,000 is not 5.5 billion.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Haha, you are right. And it was actually the bigger of the two numbers...
It was 551 billion. I was attempting not to exaggerate in my headline (seriously) and then I put the wrong number down.
|
|
|
|
|
If you toss a coin, how many attempts will it take until it comes up heads?
I'd plump for somewhere between one and infinity (inclusive).
The concept is the same, no matter the size of the pool of possible values.
Regards
Nelviticus
|
|
|
|
|
That's not random enough! You'll need a bigger bit size to get close to say simulating a shuffled deck of cards (52!). I.e. chance that a shuffled deck comes out 'sorted'.
The (linear) size of the universe, in Planck lengths, still isn't enough to even simulate the random shuffles of a card deck (leads to arguments about it being a predictable universe - don't go there .
(Size of a random card deck: Every second re-arrange the deck to a new sequence, every billion years, step 1cm along the equator, every time you pass the Pacific, empty out a 5mL teaspoon, each time the Pacific empties, place an A4 sheet of 80gsm paper on a pile, until it reaches the moon. Visit moon a million times. Almost done. Phew, ... need more Jokers)
|
|
|
|
|
Run the test again, except instead of
if (rnd === 0)
use
if (rnd < 0.000001)
Or some small number. That will give you an idea of how close to zero you're getting.
|
|
|
|
|
BryanFazekas wrote: use
if (rnd < 0.000001)
That could be very interesting. I'll try this later and we'll see what we get.
|
|
|
|
|
I thought about this a bit too.
And, remember, it is randomly grabbing a number out of a "bucket" which is a huge set of numbers.
It is no more likely to choose one that is < 0.000001 than any other range : considering this to be the range of 0 - 0.000001.
The point here is that yes, I will get more hits for this because it is a range and not just a single random value (0) that I'm attempting to get, but it doesn't really indicate much more than that.
Just some thoughts.
|
|
|
|
|
FYI - I tried it your suggestion and ran it 10 million times (only takes about 1 or 2 seconds to run).
We got 7 values < 0.000001 out of 10 million generated random numbers.
running...
rnd is 8.534479201127709e-7 in 2432341 tries - lessThanCounter: 1
rnd is 2.3682786065570838e-7 in 3184756 tries - lessThanCounter: 2
rnd is 9.513474119593468e-7 in 4548719 tries - lessThanCounter: 3
11:54:49 GMT-0400 (EDT) - Still running : 5000000
rnd is 3.635436747195797e-7 in 7235129 tries - lessThanCounter: 4
rnd is 9.258161568492795e-7 in 7321777 tries - lessThanCounter: 5
rnd is 3.1373473086127035e-7 in 7743862 tries - lessThanCounter: 6
rnd is 3.704604489840335e-7 in 8554983 tries - lessThanCounter: 7
Again, it makes sense that because we now used a range of values that the probability of hitting a value is higher and we do get the values. However, again, if we chose any specific value then we'd possibly wait forever for that value to be hit. Or, it could occur the first time.
It definitely gets you thinking.
|
|
|
|
|
Yes, I expect that we can choose any number and get the same result (no hits) as you got for zero.
I had my testing hat on -- I was wondering if the RND function is truly random, or if boundaries get missed? Your results indicate we are getting really low numbers.
Curiosity satisfied!
|
|
|
|
|
I do not know javascript but, if it works similarly to c/c++, there is a potential problem with your program that you need to be aware and I do not think anyone pointed it out yet.
The same documentation you link points out that
"The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user".
and the documentation at <a href="https://tc39.es/ecma262/#sec-math.random">https://tc39.es/ecma262/#sec-math.random</a> states that "Each Math.random function created for distinct realms must produce a distinct sequence of values from successive calls."
Depending on how the sequence of numbers is generated by the underlying (maybe system) function, you might get a fixed (although large) number of different numbers and, when you reach the end of the sequence, it just restarts the same sequence.
If the seed can not be reset or changed like it is mentioned in the documentation, you will never get a specific number if that number is not part of the sequence.
That is the main reason why cautioned c/c++ programmers reseed their random number generation functions every once in a while inside their main program loop.
You can easily test if the sequence is repeating by storing the first, say one thousand, numbers and test each time you get a new number if it matches the first number drawn. After the first number being the same, the next drawn number must equal the second and so on.
If you get the same initial sequence, it is clearly repeating since it is statistically improbable that the same (large) sequence of numbers repeats itself in a true random sequence of numbers.
I already had this problem in the past in c++ and, in one of the tests I made, I got a sequence of just five different numbers on a 32bit platform .
This is probably the reason why in the documentation is suggested to use another random number function for cryptography.
Just one note about your program. Do not use floating point numbers as increment counters in loops. They might not work as expected due to the bit limit of your platform (probably 64 bit).
Imagine your counter is already at 1.2345678911234455445656765345542e+300 and you increment one. If your counter has already reached its maximum resolution, incrementing by one does nothing and you get 1.2345678911234455445656765345542e+300 instead of the expected 1.2345678911234455445656765345543e+300 (which would also be wrong since you do not have 300 digits).
This means that the terminating condition of your loop is never reached and you get an infinite loop.
If you have no choice of data type, check the documentation and use a number close to the resolution limit of that data type. As an example, if the data type has 20 bit resolution for the significant digits then the maximum integer value it can hold is (2e+20)-1 .
Or take the "hands on" approach and make a loop in which you increment a counter and check when the number is the same as the last.
Just my random opinion
|
|
|
|
|
Thanks for posting, it was an interesting read.
Yeah, I know about the issues requiring seed. The JavaScript implementation of Math.random() handles that itself and doesn't allow us to control it from the outside.
Math.random() is definitely manipulated and is not a strong PRNG. Definitely not a CSPRNG[^].
I was curious only about one thing: Why hadn't I seen Math.random() ever generate a value of zero (even after running for days) since the documentation states that the value returned is 0 <= r < 1.
JavaScript handles types for the dev and Number is the only choice. It is floating point and I was basically attempting to create a boundless loop when I set my loop watcher to Number.MAX_VALUE (1.7976931348623157e+308). It was just a way to get it to run for hours, days, months.
Good discussion.
|
|
|
|
|
The first time I used random numbers in C, in my first programming class in university, I went through the same questions just to realize that certain numbers are simply not in the sequence generated by the pseudo-random number generator. In your example it is zero but you can probably pick any other number and the same will happen. If javascript does not automatically reseed you will have always the same sequence and never have the number you want.
Later, in university, I studied how pseudo random number generators were constructed in silicon and understood why certain numbers never show up using a certain seed. If I recall correctly (as it was two decades ago), the seed must be one that triggers the maximum length sequence of the generator and most seeds do not. If you search for "pseudo random generator logic gates" or something similar you probably find information about it if you are interested.
Curiously, I trashed yesterday one of the Springer publications from 2007 that shows up in the results
I am sorry if I sounded too aggressive about the floating point counter. Usually a "while(1)" is used for boundless loops. When I saw it I thought you were using it without knowing. Unfortunately, I already had my share of people "asking" me to fix their programs that do not stop because of loop conditions that are never met (like using integers with double/boolean/string/pointers/etc).
Best regards and keep the curiosity high
|
|
|
|
|
I'm using SQLLocalDB (MS SQL Express) for a test database.
Had to rebuild services and db on new VM Server.
All good, but then I got this error when my ASP.NET MVC Application attempted to connect.
returned to my web app... A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start. ) But, that is a lie. The instance is actually started as shown by command-line sqllocaldb info:
c:/>sqllocaldb info mssqllocaldb
Name: mssqllocaldb
Version: 12.0.2000.8
Shared name:
Owner: ZSYSTEM\USER-name
Auto-create: Yes
State: Running
Last start time: 4/2/2020 3:24:46 PM
Instance pipe name: np:\\.\pipe\LOCALDB#34729310\tsql\query
IIS App Pool
I checked IIS (InetMgr) and looked at the Advanced Settings on the App Pool to verify that it is running as me. It was and then I remembered that esoteric setting that I needed to change... (Load User Profile: set to True -- defaults to False)
But, check out the text that InetMgr provides to explain the setting. Really bad tech writing which is repetitive and not very helpful.
It's like "what does Load User Profile do?" "Well, err...umm... it loads the user profile."
I originally figured this out by trying every option, one at a time until I found the one that worked.
Snapshot of APP Pool Advanced Settings[^]
*And surely someone will say something about security and that I should be running as ApplicationPoolIdentity by default and all that. This is for development tests that is all.
|
|
|
|
|
That has got to be the worst tech writing I've ever read. They really took the speech-writing advice to heart:
Tell 'em what you're gonna tell 'em, tell 'em, and tell 'em what ya told 'em.
|
|
|
|
|
|
When was Microsoft tech writing EVER known for anything but Horrible tech writing?
Old codger
|
|
|
|
|
LocalDB stores all instance data in a local AppData folder, which is why it needs the profile to be loaded.
You might also need to enable setProfileEnvironment in some cases, as described in this archived blog post:
Using LocalDB with Full IIS, Part 1: User Profile | Microsoft Docs[^]
which links to this no-longer-available KB article:
Windows 7 SP1 causes IntelliTrace Collection to fail on IIS[^]
(Is anyone else fed up with Microsoft breaking all existing links to their content, and not bothering to redirect to the "archived" version?)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the additional info. I had also found this somewhat cryptic text which kind of explains this item:
User Profile
IIS doesn't load the Windows user profile, but certain applications might take advantage of it anyway to store temporary data. SQL Express is an example of an application that does this. However, a user profile has to be created to store temporary data in either the profile directory or in the registry hive. The user profile for the Network Service account was created by the system and was always available. However, with the switch to unique Application Pool identities, no user profile is created by the system. Only the standard application pools (DefaultAppPool and Classic .NET AppPool) have user profiles on disk. No user profile is created if the Administrator creates a new application pool.
However, if you want, you can configure IIS application pools to load the user profile by setting the LoadUserProfile attribute to "true".
|
|
|
|
|