Choosing users for A/B testing [closed] - c#

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 have a table with userid's (int increment) about 4M records.
I would like to show a new feature to only 25% of the users.
What would be the best way to choose those 25% users?

you could use some sort of Fisher Yates shuffle algorithm to randomly choose the 'first' 25% of user ids.
ie, pick a random number between 1 and 4M. that's your first user, add it to a collection somewhere. repeat until you have 1M (25%) users in your collection.
Once you have all the users, mark them somehow in your table.

Another idea is that you could set a browser cookie which was 'myAwesomeFeature=A' or 'myAwesomeFeature=B'. If the cookie isn't set yet, set it to 'B' if a random number between 0-100 is 25 or less. 'A' otherwise. If the cookie is already set, just use it.
Has the added benefit of being easily testable since you can easily force yourself to be in whichever group you want. And it'll work for multiple features since you just need to change the cookie name. And the same user will get the same group as long as the cookie doesn't expire.

How about this?
if (user.Id <= (maxId * 0.25))
{
// Show a new feature
}

Related

Generate skipable list based on chars [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 am very sure that there is a technical term for this problem, but unfortunately I do not know it.
I have an alphabetical charset and the requirement is to create the combination of all the chars with a maximum length
The idea is (sample):
Generate a collection of A, AA, AAA, AAAA, AAAAA, AAAAAA
Next: A, AB, ABA, ABAA, ABAAA
Next A, AB, ABB, ABBA, ABBAA
The reason:
We have to query an API that delivers search results.
But if I don't get search hits from the API on AAA, I don't need to search for AAAA anymore, because it can't get search hits either. I can then move on to AAB.
The question:
My problem is that I'm not sure how the code has to be built to achieve this goal. I lack the structural approach.
I've already tried nested loops, but unfortunately I don't get the result.
I also used Combination Libraries, but they focus on other problems.
Many thanks for hints!
What you're looking for is a particular data structure called a Tree, but probably more specifically in your case, a Trie.
Trie data structures are commonly used in things like Autocomplete. With the image below, if someone typed "te", I can traverse the Trie and see what options would come after that (tea, ted, ten).
It looks like this would also fit your use case from what I can tell.

How game AI to locate, identify, and Target other game objects in unity [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
How can I get my NPC AI to locate all objects within X distance, identify each object and then be able to Target a specific object?
An example being:
The AI is in an area, and there are 4 objects within it's range. Those objects are 2 tree, a rock, and a pig. The AI needs wood, and then will need some rock. How do I get the AI to be able to identify the 2 tree, the rock, and the pig, and then go to a tree, and then go to the rock?
To search for certain type objects:
var foundObjects = FindObjectsOfType<TextMesh>();
https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html
To locate them (note that foundObjects is object[], you need to loop over them):
foundObject.transform.position;
Needs can be stored in priority queue. It is basically self ordering data collection, if you solve the highest priority task of ex: finding 2 wood, it will get you the next highest priority task to do.
This question is broad, There are so many aspects to going about this. I suggest attempting one aspect / researching it. Once you come to a stump in code that you cant understand, come ask. If I had to suggest a starting point, I would look up how to code the distance from one object to another. Then look up how to do that for multiple objects in a scene. Then look up how to identify those, whether it be by Tag or GameObject, etc..
Start from there, I wish you the best of luck on your journey!

How do I generate a positive long integer in C#? [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 5 years ago.
Improve this question
How do I generate a positive long integer in C#?
Background information: I have no shared state, and am inserting entries into dynamodb, which has no auto-incrementing primary keys. A typical pattern is to insert a guid, check for collisions; depending on how occupied the table is, this is a working solution. I would like to use a modified strategy, where instead of using guids (16 bytes) I will use positive longs (63 bits).
Justification that this is a safe plan:
I expect to eventually use at most a hundred billionth (1/10**8) of the total available space.
2**63 == 9223372036854775808
if I store 100b records, occupancy is:
2**63/10**11 == 92233720 ~= 10**8
Which means the chance of collision is about one every hundred million tries. Since I detect collisions upon insert, that it is acceptable to have to retry the generation at that frequency.
So the question is:
How can I generate random positive longs in C#?
The question asks for how to generate positive longs in C#. This code does that.
The question outlines a plan to handle duplicates. Therefore the following code does not generate PKs, or claim uniqueness - it claims well-distribution and is relying on the outlined framework for handling longs.
So, here is how to generate positive longs in C#, which is what the question asked for:
public static long GeneratePositiveLong(Random random)
{
byte[] buf = new byte[8];
random.NextBytes(buf);
//the last byte must be from 0-127
buf[7] = buf[7] &= 0x7f;
long res = BitConverter.ToInt64(buf, 0);
return res;
}
One possibility is to use a table to keep track of the next PK to use for your other table(s). Lock this table when you need a new primary key, read the current value, increment it, then unlock. This way multiple clients will not overlap keys.
One possible solution is you could use currenttimestamp in nanoseconds which would be unique so that you can use it as a unique primary key as well

Generating folders using textboxes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hello experts, I have to generate series of folders from a TextBox into specified location.I am having two textboxes to specify the limit of folders(say 30 folders).The problem am facing is that the folder names that i will be providing are alpha-numeric(say 121cs3h101) .
How to set limit when i provide an alpha-numeric values?
(For example: i provide textbox1=12cs3h101 and textbox2=12cs3h131 , i need the series limit to be generated). I am working with visual studio 2013 in c# windows form application. Thanks in advance.
ok I will try to give you a lead.
To parse a string or find specific characters one can use RegEx.Match or a simler method called String.Split. In both cases you have to be aware how your string is structured and how it can vary. The limits of variation are very important.
If as you say the beginning is always"12cs3h" you can either split the string at the character 'h'.
string[] sa = s.Split('h');
Or you can even use the index of 'h' (since the length seems to be fixed) and take the rest of the string to get the numbers.
int index = s.IndexOf('h');
The rest is up to you, ... convert, enumerate and so on.
EDIT: There is a nice method that does the enumeration job for you: Enumerable.Range Good luck

How do I efficiently parse a large amount of strings? [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 8 years ago.
Improve this question
I have a database of let's say, 1000 strings. Whenever a user of my program writes a sentence, it checks the database, SELECT * WHERE trigger=sentence, and returns the data rows. Considering it's a database, this goes very fast.
For the program, though, it would be much more convenient to just load in the entire database into a Dictionary<string, string> at the startup. That'll allow me to use string.Contains(sentence), so a (sub-)sentence can be anywhere within a sentence, rather than the entire thing.
With just a thousand strings, that's fine. But what if the database grows larger, to say.. 100.000 strings? Even more? foreach (var w in dictionary.Keys) if (w.Contains(command)) //etc over that much strings, potentially a few times per second?
Is there a proper way to check such a large amount of strings?
Or am I just needlessly worrying? It seems like a lot, but computers have surprised me more often.
If your willing to create dynamic sql in your code:
SELECT * FROM YOURTABLE WHERE 'The sentence the user typed' like '%' + [StringColumn]+ '%'
This should check each string against whatever the user typed.

Categories

Resources