|
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".
|
|
|
|
|
Griff, I read your lounge message the other day about that 10 GB update for Visual Studio and today I read this report about open source projects by Digital Ocean. This part of Generational Expectations for Open Source Maintenance section was interesting.
Open Source 2019 Q4 report: Younger generations want a faster pace for updates and maintenance, reflecting their general enthusiasm for the work being done in open source. Older Gen X and Boomers, who report higher feelings of burnout, take a less hurried approach. There is even a slight difference in who these generations believe should be responsible for maintenance in open source. We expect this gap to only widen until the time that Gen Z and Millennials make up the greater part of the community. In the meantime, there seem to be some generational gaps that need to be addressed. While the older generations’ attitudes towards big tech in open source could be construed as pessimism or distrust, it may just be a matter of experience — some have decades of veterancy compared to their younger colleagues. Overall, optimism remains high across age groups and younger generations can learn a lot from their more experienced community members.
How is that 10 GB download coming?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
- I was born in 1971
- I always have Visual Studio update to the last update to the last minute before anyone else!
- it was NOT 10GB for me. Seriously I wonder how it's 10 Gb for him.
- BTW there was a Git extension update 10 minute ago, keep up guys!
|
|
|
|
|
Quote: I always have Visual Studio update to the last update to the last minute before anyone else!
Back in Pakistan, due to slow internet speed, I could not afford to update my Visual Studio each time there was an update. Now, I am in Turkey so I try to do this as well. You know, why not.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Couple of minutes, was all. (50+Mb Fibre-to-cabinet connection)
If you want to include someone, use the at-code system: and at-sign followed by the Username (not necessarily the same as the "Display name", your Display name is "Afzaal Ahmad Zeeshan", but your user name is "afzaal_ahmad_zeeshan"). If you do that, they get an email alert that you are talking to them.
You can find the Username on the user homepage, top left corner, just below the DisplayName
@afzaal_ahmad_zeeshan
Just like that!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Found this nugget in the constructor of a class that’s supposed to represent a structure in a binary file:
var isNamed = reader.ReadBoolean();
if (isNamed)
{
var nameLength = reader.ReadByte();
this.Name = new string(reader.ReadChars(nameLength));
}
The property setter for Name checks the length of the string—and it forbids zero-length strings. Wouldn’t a name length value of 0 suffice to indicate the absence of a name?
|
|
|
|
|
But, if nameLength is zero, this means that isNamed is true .
A man has no name. That's why.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Valar Morghulis!
|
|
|
|
|
The only reason i can think of for this is that Name can be specified but empty, which seems silly. I wonder if there was a design issue further downstream that required support for empty names?
Real programmers use butterflies
|
|
|
|
|
Or ReadBoolean masks a bit and they put the other 7 bits to good use.
|
|
|
|
|
If that were the case I would be skinning someone come code review time.
Real programmers use butterflies
|
|
|
|
|
But but but...it's a binary file.
|
|
|
|
|
Database people have been discussing variants of non-existing, empty and zero-length strings for at least 30-40 years.
There is a difference between not knowing whether a value for the attribute exists, knowing positively that it is void, and knowing that there is a defined value, but it is of zero length.
The strangest passport I ever saw was for the son of friends of mine: It stated birthdate as unknown, sex unknown, name unknown, no photo or fingerprint available. When the mother, US citizen living in Norway, is pregnant with a baby, and plans a trip abroad with the baby a few weeks after the delivery, you must start the process of applying for a passport before those details are known.
So for this baby's middle name, before his birth, nothing was known, not even if he would have a middle name at all. If he has one, I do not know it, so I could treat it as a defined name attribute with unknown value. If I learn that he certainly does not have a middle name, it would be a known value of zero length.
There may be better examples to illustrate various null/empty/… values; this is just the first one dropping into my mind. There may be cases where there is no semantic difference between optional omitted, included but unknown, included with a known length of zero and included with a positive length value. Yet there are other cases where the semantic difference may be very significant.
|
|
|
|
|
Empty is not the same as "unknown". If it is unknown, then that is what it should state.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
mmmm... while you are arguing for 1 wasted byte at offset 0, did you noticed the wasted 1MB at offset 43512?!
|
|
|
|
|