196 comments

[ 8.2 ms ] story [ 4415 ms ] thread
finally, a use for Math.random()
What's wrong with Math.random()? I use it all the time (graphics) and it works like a charm.
Read these articles to know what is wrong with Math.random()

https://medium.com/@betable/tifu-by-using-math-random-f1c308...

https://hackernoon.com/how-does-javascripts-math-random-gene...

https://news.ycombinator.com/item?id=10751396

https://v8.dev/blog/math-random

> Many random number generators in use today are not very good. There is a tendency for people to avoid learning anything about such subroutines; quite often we find that some old method that is comparatively unsatisfactory has blindly been passed down from one programmer to another, and today’s users have no understanding of its limitations. — The Art of Computer Programming, Volume 2, by Donald Knuth

That hackernoon post is... unimpressive. Its main argument seems to be that Math.random() uses a PRNG instead of a source of true randomness. That is not compelling. It becomes less compelling accompanied by claims like this:

> So now the question is: what PRNG does JavaScript use?

> The answer: none.

There is zero discussion of why xorshift128+ might be suitable or unsuitable for any given purpose, or of what its characteristics are. The whole thing is just the observation that, if you can understand the raw mechanics of the PRNG, you can have a good laugh at the idea that deterministic bitwise operations are "random".

It does mention that browsers standardized on xorshift128+ in the nearly-forgotten days of 2015, which would seem to make your Knuth quote inapt.

There is absolutely nothing wrong with that. What kind of random number generation you need depends entirely on your use case, and for my use cases it's just fine since "better" random number generators won't give me better results. If you really have strict requirements on your random number, then yeah, you will have to find another solution.
Here's the twitter thread in the screenshot: https://twitter.com/OphirHarpaz/status/1184486445039411201
Someone else in that thread asks:

> I wonder if they report a lower price to Google as well.

Presumably for the little boxes which show up below certain Google ads with price points []. I know that's against Google Ads' policies, but has anyone heard of it happening nonetheless?

[] https://support.google.com/google-ads/answer/2497706

Yes it happened to me, a hotel was priced significantly cheaper on Google and on their site initially. When the price went up I just called the hotel and the higher rate was their standard and only rate that they offered. The initial advertised price was never an actual option.
Isn’t that plain illegal, full stop? If that’s not the textbook definition of false advertising then I don’t know what is.
If the Lanham act applies, possibly[1]. This isn't typical false advertising, though, as it's not claiming their service does a thing it doesn't nor is it defaming a competitor, it's lying about interest in the service.

Looking at the criteria:

> (1) a false statement of fact has been made about the advertiser's own or another person's goods, services, or commercial activity;

I think a fake number of people looking is a false statement of fact about commercial activity.

> (2) the statement either deceives or has the potential to deceive a substantial portion of its targeted audience;

Seems like a false number would deceive anyone who saw it.

> (3) the deception is also likely to affect the purchasing decisions of its audience;

And it would induce them to purchase when they might otherwise hold off the decision.

> (4) the advertising involves goods or services in interstate commerce; and

It's the web, so naturally.

> (5) the deception has either resulted in or is likely to result in injury to the plaintiff.

This is where it gets dicey and you'd need to ask a lawyer, or someone familiar with case law. The source I'm citing goes on to say:

> The injury is usually attributed to money the consumer lost through a purchase that would not have been made had the advertisement not been misleading.

I think if you could show, "I would have shopped for another price if I didn't think this was almost sold out," then you might have a case.

But... I suspect your damages would be the difference in prices between booking.com and some competitor, which are likely to be fairly small. The source has a whole section on remedies that might apply.

[1]: https://legal-dictionary.thefreedictionary.com/False+Adverti...

I think you misunderstand- the parent comment you replied to is referring to ads on Google using a much, much lower price that isn't actually offered by the hotel; it's not referring to whether or not the number of people looking at the ad is misleading/false.
Oops, you're right. Oh well, it was relevant to the main article.
AFAIK Google takes this sort of thing rather seriously... if they ever hear about it.
Sure they do, unless you are a cash cow in which case you get a mild warning.
Problem is that they know almost nobody is going to try to contact Google about this, and of those that do, their emails are almost certainly going to be of ignored.
I work for Google.

You can report fraudulent ads with the form here: https://support.google.com/google-ads/contact/vio_other_aw_p...

FindHotel.com's prices are frequently understated when searching with Google Hotels. You click the link, and the price magically goes up $40, and that number still doesn't include taxes and resort fees.
I would like to report every ad for magic crystals, essential oils and SEO services.
Google should do a better job at fraudulent ads instead of waiting for a consumer to complain.
Is this legal?
How would you write a law to make it illegal?

The better remedy is precisely what is occurring: someone calls the Emperor's bluff, and we all get on HN and engage in cheeky humor.

False advertising?
How are you actually going to prove the state of a distributed system in an legally actionable way?
In the OP case, the evidence is not a problem, right? There's nothing specially about "legally actionable", you just need to convince a judge or jury that it happened, as with any other fact. In this case, with the JS code cited.
(comment deleted)
I have two reactions:

1) lol

2) This should be illegal.

Might be unlawful anyway, if you could argue that you were sold "a plane ticket being considered by 38 people" rather than just "a plane ticket".
Yes, I think it is false advertising, so should be illegal.
The only way out of it I can think of would be: if the site could prove that some number of people, greater than 45, were hitting that specific query on that specific page, then vacuously, they could say that any number of people between 1 and 45 were also looking at the offer.

But then, why wouldn't they just display "at least 45 people" or the exact number? I'm struggling to find some way of doing this which could be any stupider (`view_notification_random` ??) than what we see.

“But..” stammers the dev “I have no real way of knowing just how many people are looking at this offer.”

“But in Sprint Planning round 4 you told me the API is ready” responds the PO sternly. “Sprint ends tomorrow. I gave you the story. You committed to the goal. Them’s the rules.”

“Ok, Ok. Tell you what, I’ll make something work and we’ll write a follow up story to make this right. Does that please you, mighty Owner of Product?”

The source code literally calls Math.random. I hope that defence wouldn’t fly in court, even if accidentally true.
Always get in the seat of the defense.

I would absolutely have made a few headless browsing bots masquarading as users just incase this scenario occurred

Look your honor the logs say other users, “people”, were looking regardless of our random function

Would admitting to gaming those numbers make your defence somehow stronger? Or would you withhold that information, and perjure yourself?
Depends on the charge and the consequences of those charges
Ah yes the classic legal principle of "two wrongs makes a right".
The legal principle of custom tailoring your defense based on what the charge and consequence is, after covering your ass based on what the potential charges and consequences are

Thats the literal theme of this website’s headlines where you been

My thought (giving them benefit of the doubt) was that perhaps they knew that somewhere in the vicinity of 28-45 had been looking recently, but not with per-minute confidence. So they fix that range and then randomly pick something from that range to display on each page load. But that is giving them a lot of benefit!
Maybe, then to be truthful you can display "Approx. 28-45 people are viewing this"
It’s not false advertising. That would involve misrepresenting the product, which this does not. It’s unethical, but not illegal.
Are you sure? The value of a thing is often estimated by the interest others have in it. Regardless, it can be fraud.
I’m sure there are laws against making false claims to sell your products.
Not false advertising but surely it can produce damage by inducing hurry in the customer who then won't have enough time to make the right choice or look for alternatives.
I'm noticing that even Etsy does this by saying that "n people have this their baskets right now."

That might be so, but it's not like most of the items are scarce. For example, I ordered a t-shirt and the seller just used a local t-shirt company to produce the shirt and mail it to me since it was cheaper than mailing a shirt through international delivery lol

So some manager came up with this, tasked a PO, who tasked a team, and a frontend developer implemented it - and in this chain, in the end, everyone complied. I know it's not like murder, but especially in a field where it's so easy to hop into another job/project, one should have greater integrity.
This is why real freedom is financial freedom.

You don't like what's going on at work, find another job.

I have to agree. I know that for some people it's not easy to just find another job for various reasons, and I've had that problem myself over the years - but there is a line you just don't cross; this is such a line. Deliberately and purposely lying like this is never OK.
Can't assume they don't have integrity. They might just have different moral values.

I would gladly implement this any day. Its not illegal.

> Its not illegal.

Fulfilling your basic legal obligations is not the definition of integrity, and often the two are at odds.

what is your definition of integrity ?
Integrity -- the quality of being honest and having strong moral principles; moral uprightness.

The definition of integrity requires honesty. Do you think it is honest to tell people "there are 38 rooms left" when you know 38 is a random number?

The definition also requires you to act morally. Do you think that anything legal is moral, and vice versa?

Slavery was legal. German extermination camps were legal. Were these moral?

Smoking weed is illegal. Is it immoral?

Morality is subjective, according to my moral framework, telling people there are 38 room left, if I'm the business owner and the benefit > cost then yes.

Same thing with slavery, extermination camp, weed. To some people these are moral.

Frankly speaking, your moral framework needs work. Sincerely, the rest of society.
Its normal. You may disagree with my morality and me or other people may as well disagree with your morality, whatever that is.
Out of curiosity, are you an atheist/agnostic?
Any moral framework that attempts to justify outright lying in order to obtain personal gain at others' expense is not only not normal, it is also indefensible.
Normal as in I don't expect everyone will agree. There is no moral framework that everyone will agree anyway.

Whether its indefensible or not, is matter of your preference/personal value.

Brother, you need to grow the fuck up. Right now, you're coming across as one of those try-hard college students on a 'Rationality Rulez' bender.

Morality is subjective but not in the manner you're describing. It's not arbitrary. Our values are conjured out of thin air but for reasons that DO involve the betterment of humanity.

Slavery isn't subjective, and extermination camps sure as hell are not either.

Sometimes is not, some people values does not involve the betterment of society. Unless you claim everyone think alike.

How is slavery or extermination camps not subjective? The slave owner may think slavery is good thing but the slaves may think its horrible.

It is almost certainly illegal. The use of falsified facts in an advertisement is illegal.
>almost

That it mean not illegal ?

The dictionary definition of fraud:

  wrongful or criminal deception intended to result in financial or personal gain
> They might just have different moral values.

This is why "values" is a terrible word to use to describe morals.

Values are subjective things like modesty or frugality. Those are values, because how you dress or spend your money generally have consequences only to yourself.

Something becomes immoral when it deprives another person of their inalienable rights; it causes them harm. Others' rights aren't subject to negotiation, that's what "inalienable" means.

That one can often get away with bullying or lying might make it seem like it's just a personal choice. That is, until people get fed up with it and hold that person to account for their actions.

Same thing with morality, its subjective.

There are no such thing as inalienable rights. Every right has to be earned and fight for.

One of the ways you earn and fight for those rights is by not claiming they don’t exist. There are already enough people in the world who think you don’t deserve those rights. Best to keep the goal posts far away and convince as many others as you can that that’s where they belong.
Yes, any rights exist because someone earn it or fight for it.

Its not just given from god or something.

And yet tribes and nations that recognize and protect inalienable rights are consistently able to defeat those that assume the strong should have power over the weak.

The reason being that individuals living in societies with inalienable rights feel they have more worth fighting for, and they are more industrious and able to build robust trust networks.

None of that is subjective, it's all how the universe works, so, yes, you could plausibly attribute it to God or any kind of creator.

The strong does always have power over the weak. The right that exist right now is because someone powerful enough to fight for it and maintain it, otherwise those right doesn't exist.

Rights are subjective, meaning it depends on the particular society, even it may have different meaning to everyone. Example: The rights for woman in Afghanistan and USA are different.

But people will reliably fight for it, that's an objective fact.
Agree, some people will fight for it, some people will fight againts it.
> tasked a PO, who tasked a team, and a frontend developer implemented it - and in this chain, in the end, everyone complied

You have only worked on big projects, right? This could be on developer.

It could also be a FE change that was supposed to be hooked up to the backend, but went out early.

This would not surprise me. If I had a dollar for all the stupid crap I PRd that got caught by peers. If its a small team with no peer review... Whoops. Hard to say why this is till they change it.
> It could also be a FE change that was supposed to be hooked up to the backend, but went out early.

Quite likely this. Passes all requirements tests. So follow up story to add real data is still in the deep frozen backlog. May get promoted to ready in year never.

I want to add Hanlon's razor to this.

Some are pointing straight to malice and intentional misleading.

It wouldn’t surprise me if they wanted to make it genuinely work originally, but realised they could save a lot of money, resources and sprints just faking it in js.

More laziness and “oh shit this project was bigger than we thought let’s find a shortcut” than outright malice.

I wouldn’t be surprised if it genuinely worked to begin with, but the numbers were lower than they expected so then they just made it random.
That's not Hanlon's razor: they had a moment where they commit an act of fraud by intent, not by incompetent behaviour.
The point is, rather than setting out to maliciously deceive people it could have just been laziness.

There’s multiple angles to what could have happened.

"I'm going to commit fraud out of laziness" is plenty malicious.
For another example: for about two years, Twitter on the web had a feature in the notifications section, a dropdown on each notification item with a "See less often" option which appeared to the user to send feedback or preferences to Twitter, but in reality sent nothing.
The Twitter thread pointed to a BBC article [1] that certainly suggests that the UK’s regulators don’t think this is okay. I’ve found that Booking.com legitimately treats independent rooms as “only one left” (e.g., the B&B has named rooms, so there’s always just one of a kind for each) but I suspect any investigation into most of these sites leads to “this is full of misleading dark patterns”.

[1] https://www.bbc.com/news/technology-49740143

Booking.com is horrible to use in my opinion. It is handy but you need to ignore the dark patterns on every. Single. Page.

Honestly it makes me want to use the website less, and does not urge me to buy.

I wonder about an app that just has phone numbers and a short description of hotels. If there are 50,000 hotels in the US, and you store 1K worth of data, that's only 50M. You could keep that on a phone no problem.
Sadly that list doesn't answer the most important questions - do they have availability for a particular date, and at what price
Hotels have this thing where you can call and a human will pick up and you can ask them questions. Like do they have a room available.
Imagine being able to go to one website, entering a location and dates, and seeing availability and prices all in the one place.
Imagine much of it is dark patterns and bullshit.
You might have a point there ;)

So you ring the hotel and the person who answers, if they’re worth their salt, tells you there’s only one room left / there’s a big convention on in town / everywhere else is likely fully booked out, and closes the sale.

I've called, been told no rooms, and then told that some other hotel has a room. Or told that someone canceled 15 minutes ago.
Do you frequently book hotels or travel? Just wondering because the app that you describe is so woefully short of even reasonable expectations, let alone what we have right now.
Once I checked Agoda to get an idea of the room prices in the area I was visiting, but decided to get the room directly from reception assuming that the price would be the one I saw on Agoda minus their commision. I was wrong, the price was about 15% more expensive at reception and it didn't include breakfast. I pointed to them that I could get the room cheaper from Agoda and they told me to get it from Agoda then. I sat in the lobby and booked the room online.
Yes. This happens a lot.

Often it's because the Hotels don't have an proper direct booking procedure in place and getting a direct booking is a hassle for them.

In many countries though they are not even allowed by Booking to give a cheaper price which shows the power they have.

> getting a direct booking is a hassle for them.

You'd think they'd be a bit more willing to take peoples' money

Been there, done that. There's another difference if you book your Thai hotelroom in Thai versus in English.
Last time I had a phone screening with the, I learned their entire codebase was in Perl, with no plans on migration to anything else. There were almost no unit tests anywhere. Most developers could push directly to production.

Everything the girl on the phone said was horrifying and I decided not to continue. Their recruiter kept trying to call me over Skype though, and they offer more than most other companies of that size in the EU, so I suspect they're pretty desperate.

This was back in 2015 so maybe it's changed, but it sounds like a terrible place as far as technology and tech debt goes.

> their entire codebase was in Perl, with no plans on migration to anything else. There were almost no unit tests anywhere. Most developers could push directly to production.

One of these things is not like the others. Not liking Perl is a valid personal choice, but doesn't say much about the codebase. The others are telling though. More so if it's true given that Perl has a very heavy culture of testing (the TAP protocol comes from Perl, and Perl is known for being very test heavy in its module ecossytem), which means they would be going against that culture to have no unit tests.

That said, I'm not sure if we should consider "the girl on the phone" doing the screening as knowledgeable about the process. That description doesn't convey that you thought very highly of her, so I'm not sure why we should take her word as authoritative...

The third hand knowledge I have of booking.com was that lack of unit tests was an explicit choice. I.e. they felt it was more efficient to just catch bugs in production and be quick to fix them than spend time in unit tests that got obsolete fast and add friction.

I didn't buy in the narrative, but it was an interesting perspective.

I agree, that sounds like management being afraid to deal with the technical debt they've accrued.
You’re not the first to mention Bookings lack of tests. Supposedly it’s because their code has a very short half-life, gets rewritten in no time and thus tests are seen as a hindrance.

Not that I agree, but it’s what I’ve heard.

I'd say that's a better reason to write tests :)
One should understand that at Booking, the only thing that counts is "conversion". In other words, the ability of converting a pageview into a reservation. Because that's the part of the process that creates value.

Since hotel reservations refer to a real world, where people change their plans, hotels get overbooked, burn down, are not reachable because of strikes, volcano eruptions, etc. etc. there is a huge customer service department. These people are able to cancel reservations, or force availability (after consultation with the hotel). In other words, until people have stayed at the hotel, and the hotel gets the bill for that, it really does not matter whether something was correct or not: the customer department can fix any problems.

So the only valid test is really: does it convert? And this is very closely monitored in close to real time.

The financial part of the system is thoroughly tested, as Booking.com is a listed company, so the scrutiny is extra severe.

> Most developers could push directly to production.

This is facilitates ownership and empowerment. You need to be sure that what you're doing, will not break things. If you are, it should be ok to push to production. If you were wrong, then that's ok the first time. Just don't do it again for the same reason: always make new mistakes!

This was the situation in early 2012, when I basically retired. Things have changed since then, but I still think the above is still basically true.

My brother loves Perl, so when he was looking for a job, I recommended Booking. I don't think he ever even applied for a job there, though. Possibly because of all the dark patterns.
I still use booking.com quite frequently, but the dark patterns are starting to annoy me. I wish there was a better alternative tho, yes, I could book from hotels directly, but I still need to find those hotels, that's why I use something like booking.com. I've had hotels outright tell me to just book through a third-party booking website, since they didn't have their own booking form.
(comment deleted)
Best thing to do is find a hotel through booking and then book directly. Many hotels give you a discount for it too, because they don't need to pay Booking.com.
I recently had to book a hotel in Essen during the Spiel! game fair this week, during which nearly all hotels are sold out.

Using Booking.com, I could only find hotels that were too expensive or too far away. Using a different site, I found a really affordable one near the Oberhausen railway station, at half an hour from the Messe in Essen.

So Booking isn't even all that convenient. Yes, they have a lot, but they're also missing a lot. It pays to shop around.

A lot of hotels will also spread their stock over a lot of sites to limit overbooking and micro management. They'll put 5 rooms on booking.com, 5 on expedia, and 5 spread around a dozen other places. There's no confirmation step like with deliveroo because the industry evolved with much less real time communication. So as far as booking.com knows there is only a few left. At least that was the case >10 years ago when I worked on automating this stuff.
I love imagining the Jira ticket for these.

“As a desperate guy trying to save his marriage with a last-minute holiday, I want to know just how many other lost souls I am competing with, so I loose what little dignity I have left”

"As an evil corporation, we need to make money, so we'll lie to the customer."
I like that these things are being revealed and I previously read stories that these techniques were getting less effective since more people are aware of them. That's at least half the battle. Legal punishment of this behavior is not something I think I would support since I would be worried about it being impossible or at least very hard to enforce properly.
Governments the last few decades seem to insist on the power to seize the electronic money of just about anyone. Not sure that's a happy development, but as the capability's there anyway, couldn't one just serve the advertiser an order to defend their false claim in court and take the fine out of their bank accounts if they don't show?

I'm being facetious here, but not entirely.

> Governments the last few decades seem to insist on the power to seize the electronic money of just about anyone.

Going tangential here but that is why Bitcoin is so powerful. Because it takes that power away from government.

A dark pattern implies something that is intentionally misleading. This is just lying. This is not a dark pattern because it’s Worse.
Lying, just like "parallel construction".
I mean, you can't be sure they're lying. Odds are nonzero that 38 ppl were looking at that flight
>I mean, you can't be sure they're lying. Odds are nonzero that 38 ppl were looking at that flight

I suggest you click on the link, they absolutely are lying. They're using JS to generate a random number between 28 and 45. If there happens to be 38 people looking at that flight it's entirely coincidental.

You don't do sarcasm, do you
It is lying. They claim something that they have no evidence for. Whether the number truly is 38 at that moment is irrelevant in this case. Because if the number was 0, 42, or 1437 they still would have made the claim that 38 were looking at that flight.
In any negotiation, nobody should take (at face value) the reported interest of the other party. A real estate agent could say a dozen people dropped by the home earlier today. You'd be foolish to believe it. You'd be foolish to believe Booking.com saying there's 1 room left, or the number of people currently looking at a webpage.
Why shift the blame to the victim? Is "you shouldn't lie" really so controversial?
It isn't controversial. But we should teach people to think independently, rather than devaluing education and critical thinking. Why not have both? Businesses should have integrity and consumers should be able to apply a basic level of critical thinking. I don't think I placed blame on the victim, either. I'm merely pointing out people should think critically of what they read, because that has a lot of valuable applications in life, beyond outside of protecting yourself from people who will lie to you.
I think we should also teach people some epistemological self-defense. People caught on lying should be punished, hard. Lying to others is an inherently hostile act.
Deceptive advertising is already under the FTC’s purview
That's good, but I'm talking about lying outside of deceptive advertising. There's plenty of lying going on in sales&marketing that doesn't reach the level of being illegal. Puffery comes to mind.
Sure, randomly picking a number is bound to land on the right answer eventually, but the website is still lying because it is telling you 38 even though it doesn’t actually know that. It is assuring you something that it provably doesn’t know. That’s a lie, correct or incorrect.
Lying is also intentionally misleading, so I'm not sure if your conclusion makes sense. Plus I would assume recurrent lying falls under the "dark pattern" category -- it certainly isn't a good or neutral pattern.
We don’t need another word for lying. Dark patterns are trying to trick your users into doing something they didn’t want to. The term exists because other terms didn’t capture this undesirable behavior well enough, and it need not be expanded to literally anything negative.

And not all sales/marketing tricks are inherently evil. I don’t think eBay telling you how many users watched an item in the past hour is immoral so as long as it’s accurate.

Disagree. "Dark patterns" exist because enough people talking about them are also working in or tangential to marketing, which makes them uncomfortable calling it what it is - lying, abuse, dishonesty, malicious activity, exploiting people. "Dark patters" is just an euphemism.
Lying is stating something untrue as true. A dark pattern works on implicit assumptions to get people to believe something without having to state it.

Lying is fraud, plain and simple, the laws and courts nailed that hundreds of years ago. A dark patter may be fraud, or in some way illegal, or may not, depending on details and jurisdiction. Those details might also include intent. An accidentally bad UI that costs customers money is not the same as a UI that purposefully leads customers to the same situation depending on what you're trying to determine (i.e. was the law broken, or is the UI not good).

Lying requires intent. For example, if I did not follow the US elections, thought that the President was still Barrack Obama and someone asked me who the President was and I said 'Barrack Obama', I would be wrong, but most people would not insist that I am lying. Lying is a moral statement about a person or an organization. The truth or untruth is largely secondary.
Maybe they know that statistically, based on their historical traffic, there are between 28 and 45 people visiting the page. Calling 28 + rand(45 - 28) is certainly much more efficient than fetching the data on the fly.

That would be the most charitable interpretation.

There's a product I've bought regularly at Amazon, it perpetually has 3 or less left in stock, but never goes out of stock.

Also I was buying airline tickets and Delta told me there were just 2 left at this price for ... a plane nearly 70% empty.

> Also I was buying airline tickets and Delta told me there were just 2 left at this price for ... a plane nearly 70% empty.

I don't think that's a contradiction given how many price tiers there are. Next price may only be $5 higher though.

In delta’s case that is correct. There are two left at that price (in that fare bucket). After they sell those seats, they will be selling from a higher fare bucket and the price will go up
Maybe but the pricing charts I've seen show fairs rising and falling.

That may be the case at the moment but if they shift those buckets I think it is also untrue unless it says 2 left.... unless we just change the price later.

buckets (a.k.a. fare classes) can change in price. Also, some airlines will not sell certain fare classes on certain days or release all of the fare class seats at once.

The airline definitely isn’t lying when they say there are a certain amount left at that price. I’ve seen the price change at those exact amounts when booking tickets for groups of people individually.

For airlines that's probably true. I fly United quite a bit and they have an expert mode where you can choose specific fare classes. Even within "deep discount coach" there are different pricing tiers like K, L, G, S, or T. That doesn't include "discount coach" or award booking or business or full fare coach.

The only potentially troubling aspect is that they don't tell you how much more expensive the next pricing tier will be.

If this was something that was merchant-fulfilled (not shipped by Amazon), 3rd-party sellers can use one of Amazon’s API to perpetually keep 3 (or however many) items in stock no matter how many they have on hand.

There’s lots of hocus-pocus beliefs out there about the “optimal” number.

one of my friends used to work for Agoda as a software engineer who said similar things about his company using dark patterns to fake urgency. This is very common in the travel industry and i've seen many companies employing similar tactics.
Agoda seems to be owned by Booking Holdings which I think implements these kind of dark patterns most aggressively.
If you work long enough on web-based software for a wide enough variety of companies, you too will get a chance to refuse to write that feature.
The responses in the redit thread are interesting: So many people claim they have experienced legitimate versions while making a purchase, although provide questionable evidence to support that it was valid. Is this some psychological bias for buyers?
You can look at practically any popular Reddit thread complaining about X, and find dozens of anecdotes about how they also had problems with X. Once you see these threads enough times, you start to wonder how many people are discussing an actual personal experience, vs. parroting what they've read or heard from someone.

I'd be interested to know if there was some type of scientific or trade name for this kind of behavior.

In any case, bear in mind that the plural of anecdote is not data.

This absolutely works on some sites. Home Depot is a legitimate example. If their app says there are 3 of something on the shelf there usually is exactly that many. If you buy it and check back in the app the inventory goes down immediately.
Love this: HN link to Reddit screenshot of a Twitter thread. Welcome to the modern web.
Funny thing is that it works. 15% CR uplift in the last website where I tested it
Of course it works, because lying to people to instill a sense of urgency plays on our base emotions and gets us to do things we might not rationally do.

Sellers of snake-oil and other fake "remedies" have been using this sales tactic--"your friends and neighbors have already tried it, look here, see this line of people ready to buy!" that are all plants--since the days of the horse-and-buggy.

Doesn't mean we should still keep lying to our friends and neighbors.

There are some organizations (though I don't know how plentiful) that use real data to derive these alerts. And I'd say that as long as it's all above-board and not fake data, that 15% is legitimately earned.
Thanks for making the world just a little bit worse :(
And I always assumed they use some sockets to sync that count from server. How dumb to just fake on the client side.
%99.999 of people aren't going to look up the legitimacy of this. Why spend development effort where the likelihood of getting caught is so low. And even when "getting caught" isn't that big a deal.
Because the FTC only needs to look at it once for them to give you a big fine or put you out of business. They take time but they do get around to these things. I was watching an old taped documentary on YouTube, and when I looked up the products in the commercials a good number of them were taken down by the FTC.
Takeaway: Just create a GET /current-viewers?id=42 endpoint and generate the random number on the server.

It'll satisfy all the HNers calling for legal action / off with their heads.

In a mobile app one wouldn't even have a way to investigate this.
I don't know about iOS, but at least on Android it's easy to decompile Java. Variable names aren't going to be the same, so you won't see the deliberate intent as you see here, but you'd still see that the number was randomly generated.

Now, if they generated the value server-side then we'd really never know, whether it's a mobile app or a web page... not that I want to give scumbags ideas, but this is pretty obvious.

Why is that? You can easily look at the requests and see where the numbers are coming from. It's not as easy as right clicking in the browser but if it would be a normal Desktop app it would also not work like that.
Because they are being generated locally using Math.random.
I imagine sometime in 2030 when a 60 yo uncle/aunty sees this "38 people are looking at it", calmly right clicks on the HTML elements and sees the use of math.random and says "Nope, bye bye stupid website".

I think these tricks are closing on their end of life as percentage of internet-native people are increasing.

Except with wasm and mobile, being able to look at source code will probably also be a thing of the past.
I think it's natural to feel like the populace is heading to a more competent place as the elderly age out, but anecdotally I think the opposite might be true. I've met kids in middle/high school who didn't understand how to do rudimentary OS operations, resolve email disconnections, update apps that didn't come from a store etc. The worst was when I taught a semester as an adjunct. Most of my students simply were unable to zip files together and send them as an attachment... Internet native in the iOS era is seemingly much worse than the XP era
The next generation are being raised on iPads, computer literacy is plummeting because they're only exposed to appliances, not real computers. It's sad, but it's good for our job security!
It'd be difficult to infer that Math.random was used, purely by the element inspector. You'd actually have to sift through JavaScript code, which may or may not be minified (likely so, though).
Incredible that they would implement such a dark pattern using easily discoverable client-side code.

I've seen these kind of messages before on several travel sites, and always immediately figured they were bogus, but I obviously can't be 100% certain they didn't influence me in some way - but how can it possibly be legal to deliberately lie like this to try to trick people into giving you money?

It’s not legal (false advertising) but it’s not something anyone will sue over because of how hard it is to show damages
cheapoair.com did a similar trick on me few years back.

I searched flights and after finding my flight, I clicked book. waiting for few seconds with a spinning thing , I got error message that the airline increased flight price, and I have to pay the new price.

So, I went straight to airline website to check their price, and it was lower than the first low price cheapoair showed me.

since then, I always check direct pricing before booking

I've experienced the opposite case, got a flight suggestion by a booking agency, checked prices for the same flights directly at the airline, and they were higher.
Wow, if you are going to do this, at least have the JS call some endpoint like "/check-how-many-people-also-want-this/some-id" and name the element "how-many-people-also-want-this". As a dev tasked with implementing this dark pattern that is the least you could do.
Before anyone has any interest in replicating this - keep in mind that:

Trust is earned. Credibility is built.

Go long - don't create fake social proofs and ruin your own reputation. I can say with assurance that nobody in this thread will buy anything from OneTravel or their founders again.

Counterpoint: I had never heard of OneTravel and now in a little while I will have forgotten about this incident, but the name recognition will still exist for me, and therefore I'm more likely to trust them.
I dont really care as long as I get a good price, just happened to purchase something from them a couple hours ago even knowing all this stuff.