« first day (4073 days earlier)      last day (868 days later) » 

 
4 hours later…
10:07 AM
[Captain Obvious] It's not though
[Captain Obvious] Well, it's presented like that, but internally it's just numbers
[Captain Obvious] Including all the magic numbers
 
 
1 hour later…
11:19 AM
Hi all
 
 
1 hour later…
12:39 PM
Hey @Alex :)
 
1:06 PM
 
1:31 PM
'sup
 
1:53 PM
 
2:32 PM
Hi zjbrown and everybody
Need to generate a random two-digit alphanumeric value where the first character is a number and the second is alpha. This isn't for a password so security isn't a concern. Looked at this: stackoverflow.com/a/15249297/177416
So it needs to be like 4T or 3W
The alpha is uppercase only
Digit is 1 - 9
As 0 can be mistaken for an alpha uppercase O
Thinking the GetLetter method linked can be reused: reduce the random pool of chars and fetch the alpha. Then fetch a random number from 1 - 9, which is trivial
 
Enumerable.Range('1', '9').RandomElement()
private T RandomElement<T>(this IEnumerable<T> elements)
{
    var list = elements.ToList();
    return list[new Random().Next(list.Count)];
}
iirc, there was a weird way to do random element from an enumerable without turning it into a list, but I cant member
 
[milleniumbug] new Random().Next(...)
 
:O
 
[milleniumbug] if it worked like that, it would be a static function
 
you could pass in the random as argument if you want to reuse the same instance
@milleniumbug it does work like that
 
2:46 PM
[milleniumbug] you get a "random" number based off your current time
 
but (in C#) creating multiple Random instances in fast succession will yield identical sequences
in Java, the precision at least was so small that you couldnt get multiple identical sequences even if you tried
difference between nanoseconds and milliseconds iirc
 
[milleniumbug] I have to admit, Java standard library is slightly better at this, due to not only doing a simpler thing and not fucking it up, but it also did a slightly better thing later on
 
if you need a seeded random or reuse a random multiple times, then yes, you would have to re-use the same instance
 
[milleniumbug] both languages suck tho at this
 
the level of sucking that is still acceptable is the question
 
2:48 PM
[milleniumbug] tho, in general, random number generation in most languages is pretty shit
 
Random (in java) is a fine implementation
just dont use it for security purposes
and iirc, also dont use it concurrently
 
It should work concurrently. But depends on what you expect out of it.
 
even if an RNG is inherently thread-safe, it would still produce identical numbers on the various threads if called in parallel
 
If you have multiple threads drawing from one pRNG instance, then you're not getting uniformly distributed random numbers, since you're partitioning the sequence between them
But that might be OK. However, if you expect uniform distribution in each thread, that would be a problem.
 
I expect pseudo random distribution
but afaik, a thread-safe RNG simply has to lock
 
2:53 PM
Thanks. It's going to be checked against the db to ensure there's no duplicate
 
since the output of the previous invocation is the input of the next
 
@Wietlol Yep, it's what Java's one does. Multiple threads might slow down due to concurrent access.
 
Thinking this'll work for random char:
public char GetLetter()
{
	string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	Random rand = new Random();
	int num = rand.Next(0, chars.Length);
	return chars[num];
}
@Wietlol Or this
Wietlol's solution is generic for any list
And this will generate the character array: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
Thanks, everyone, for your help :)
 
You can have a very simple thing that gets an array and returns random number from the array. Then call it with the characters you want GetRandomFrom(new[] {"A", "B", "C"}) or GetRandomFrom(new[] {"1", "2", "3"})
 
my solution is generic for any list... and will break for some
 
2:59 PM
Yep, either way
Hadn't seen Enumerable.Range('1', '9') before
 
I use it a lot in kotlin
 
Ah...I see I re-stated what Wietlol already implemented :D
 
('0'..'9')
I assume it works the same in C#
 
JS has something similar I think
 
JS probably does... and it probably breaks
 
3:00 PM
JS - not really. Don't think C# generates ranges, either but I'm less familiar.
 
Yep. JS is flexible to the point where it'll break things silently
 
"130" > "129"
but
"120" < "13"
 
"Alice" > "Bob"
 
@VLAZ except that "Alice" < "Bob"
 
Correct, because you're comparing strings. It's false. Before you edited the message, it was also comparing two strings and getting false for exactly the same reason as the Alice and Bob example.
So, let's restate it with the edit, then "babc" > "abc"` but "babc" < "bba" - it's entirely consistent. Strings are compared as, unsurprisingly, strings. It would have been more surprising if strings were not compared as strings in some cases (if they contain numerics only).
 
3:09 PM
the problem is that Javascript pretends that strings are fine to be used as numbers
which confuses a lot of starting developers
 
Well...only for the loose equality. Which, yes, is a huge mistake however it doesn't mean that strings are numbers in all cases.
 
A wild Erlang appears alice > 3
 
Most notably it's when starting developers do "4" + "2" and they get "42".
 
Hope to learn TypeScript and use that as a protection against all the loose data types
 
Just never use any.
Also, try to never use type assertions data as whatever
@Wietlol Just tried it - ranges work in C#. Cool! I'll keep that in mind.
 
3:15 PM
meanwhile, someone sent me a typescript definition and said "here, do the same in C#, so I can call your service"
 
*bangs desk in head*
 
and that TS definition contains
- union types (with primitives)
- keyof
- Omitted types
- function types
- anonymous types
- oh, and any types
 
That's actually worse than I imagined.
Usually you adjust the types based on what the backend sends.
Not the other way around.
 
Any? Hmm. Then TS might not be the ticket outta of bad practices I'd hoped
 
@Alex Hence why I said to never use it.
 
3:19 PM
TS is "here is javascript mess, try to define how the mess looks" rather than "sanity over JS"
 
It's a very common beginner problem. "I thought TS would magically protect me. I used any and it didn't guess that I was wrong"
Same with type assertions. "I thought TS would magically figure out that I lied to it."
 
TS is just JS in a fancy dress
 
It is. And too many people don't seem to realise it.
 
Okay, important safety tips. Dang
 
We get many questions on SO that are like "How do I sort this array in TS" or similar.
 
3:30 PM
Good to know TS isn't a panacea
 
 
3 hours later…
6:13 PM
Hi all,
what is a contractor, I just received a job offer from European company, but it states that I'm a contractor, but I don't understand what does it mean, so I headed here for help, sorry I don't know other place to ask for help
 
Contractors usually don't get any benefits, are paid hourly, can be let go once the contract is over. As a contractor you're responsible for your taxes as self employed
Contract workers, however, can earn higher pay than salaried
Some companies convert contract positions to full-time. They use it as a probationary period to see if the worker is worth it
My first job was as a contractor out of uni
 
thanks for the reply and info,
they mentioned I will send an invoice.
Is that required to be paid? how it works?
 
Yes, you'd send an invoice of the hours you've worked so they can bill their customer
 
Issued as a contractor... umm
does that require me to be a company? or I just head to Google docs and make an invoice, or it has a structure and should be recognized the government (for the taxes..)
 
6:38 PM
In the past, the company provided me with the invoice. I just had to fill it in
No, you don't need to be a company yourself
If these folks don't give you an invoice to fill, you can find one out there
Lots more out there
 
7:09 PM
@Alex Thank you very much, this is a lot info to me
 
You're welcome
 
 
3 hours later…
9:58 PM
 

« first day (4073 days earlier)      last day (868 days later) »