How to get a random name (out of many) (1 Viewer)

Rudgar

Content Creator
Joined
Nov 18, 2016
Ahoy all,
a part of the dialogue project I'm working on (yes, it has to do with slaves) needs to pick randomly a name from a bunch of available names and I was in the mood to write something that can maybe used commonly.

I know it's not completed yet for I have added a flag to mark those names that have been taken already, but I don't react when picking a random name that has been picked before already. The main reason is that I'm still not sure about HOW to react then. Picking the next free name? the first free?

Whatsoever: if you have some time left and you'are in the mood to check this out - I'd appreciate any comments, hint, suggestions, ideas, a.s.o.

Respectfully,
Rudgar
 

Attachments

randomname.txt
6.9 KB · Views: 216

randomname_genderonly.txt
4.9 KB · Views: 221

Last edited:

aztlan

Casual Client
Joined
Sep 14, 2013
Clever, but seems kind of like overkill...

You can just use the fact that that dialogue will randomly select from among (unchosen) lines with the same name:

start:"[NameF_INSTANT]" {"style":"Him"}

NameF_INSTANT:"[NameM_INSTANT]"{"style":"Him","set":{"NameF":"Alice"}}
NameF_INSTANT:"[NameM_INSTANT]"{"style":"Him","set":{"NameF":"Betty"}}
NameF_INSTANT:"[NameM_INSTANT]"{"style":"Him","set":{"NameF":"Candy"}}

NameM_INSTANT:"[NextLine]"{"style":"Him","set":{"NameM":"Alex"}}
NameM_INSTANT"[NextLine]"{"style":"Him","set":{"NameM":"Bob"}}
NameM_INSTANT:"[NextLine]"{"style":"Him","set":{"NameM":"Carl"}}

NextLine:"I am *NameF* and you are *NameM*."
 
Last edited:

Rudgar

Content Creator
Joined
Nov 18, 2016
Clever, but seems kind of like overkill...
Wouldn't be my first one :wink::oops:
You can just use the fact that that dialogue will randomly from among (unchosen) lines with the same name: [...]
Aye, I thought about this already. But how do I mark the names that have been picked already when I pick a second one?

On the other hand: Do I have to mark the names that are picked already when it is guaranteed that no line will be picked a second time before ALL lines with same name have been picked before?
Is it guaranteed at all that from a bunch of lines with same name each line will be picked only once until all of them have been picked?
That was one of the reqirements I had in mind when writing my "overkill" : no name duplicates.

The other requirement was that getting a random name should be usable as a kind of a function, returning to the line logically followed by the one that "called" it. But this could be added easily to your solution. As well as the third requirement: the ability to store the generated random name to a configurable variable name, e.g. the name of a Dominatrix has to be stored elsewhere than the name of her slaves.

But thanks for your inspiration! I'm heading for y office desktop anyway and will rewrite my dialog based on your idea - thank you!

Respectfully,
Rudgar
 

Pim_gd

Content Creator
Joined
Jan 25, 2013
How to shuffle a deck of cards using a random number generator?

It's pretty easy once you know the trick...

There are 52 cards. Pick a random one, lay it down.

There are 51 cards. Pick a random one, lay it down.

There are 50 cards. Pick a random one... lay it down.

Until all the cards are gone, which is when the pile is shuffled.

Imagine you have a list of names.

name1 to name52

Pick a random one.... (namesLeft = 52)

[SETVAR_number_*da.random x namesLeft \ 1 + 1*] (lets say number is 17)

Then swap the last and the random name.
[SETVARBYNAEM_temp_name*namesLeft*][SETVARBYNAEM_name*namesLeft*_name*number*][SETVARBYNAEM_name*number*_temp]

Decrement namesLeft by one, and do it again. Until there are none left. Make use of _INSTANT to do it without delay for the user.
 

Rudgar

Content Creator
Joined
Nov 18, 2016
Shuffling the "cards" (names) is not my problem, I think. I know (and use) the described algorithm since the early 90's.
But I think I got your idea of how to make sure that names are picked only once: just swap the picked one with the one at position *namesLeft* and decrease namesLeft then by 1.
With that the picked names are out of range for the next random value.
That is ... more or less brilliant. At least brilliant enough to impress me.
 

Pim_gd

Content Creator
Joined
Jan 25, 2013
You could call it a selection shuffle. Think like a selection sort, but the sorting is random.
 

Rudgar

Content Creator
Joined
Nov 18, 2016
OKay, just for the records:

One of my questions was:
Is it guaranteed [...] that from a bunch of lines with same name each line will be picked only once until all of them have been picked?
The correct answer is: no, it's not guaranteed. this little test dialogue proves it:
Code:
#DialogueChecker-IgnoreObjects#
dialogue_name:"randomonce"
all:"CLEAR"

initial_settings:{"count.a":0, "count.b":0, "count.c":0, "count.d":0, "count.e":0}

intro:"[random_line]" {"style":"Him"}
general:"[random_line]" {"style":"Him"}

random_line:"A[random_end]" {"style":"Him", "set":{"count.a":"+1"}}
random_line:"B[random_end]" {"style":"Him", "set":{"count.b":"+1"}}
random_line:"C[random_end]" {"style":"Him", "set":{"count.c":"+1"}}
random_line:"D[random_end]" {"style":"Him", "set":{"count.d":"+1"}}
random_line:"E[random_end]" {"style":"Him", "set":{"count.e":"+1"}}
random_end:"| A = *count.a* | B = *count.b* | C = *count.c* | D = *count.d* | E = *count.e* |" {"style":"Him"}
With this, I have to sincerly thank A aztlan for his inspiration, but I kinda need this "overkill" actually to meet my requirements.

Now I'll give this selection shuffle thingie a try ... you'll hear from me. Meanwhile I'm still open for ideas or suggestions.

Respectfully,
Rudgar
 

Users who are viewing this thread

Top


Are you 18 or older?

This website requires you to be 18 years of age or older. Please verify your age to view the content, or click Exit to leave.