Random Quests

Good night people!! :smiley:

I’m looking for tips to automate a process. Basically I have 30 test questions saved in a Word document and I would need to randomly select 20 of those, could you help me? I’m a beginner and I still haven’t been able to develop a solution for this

Can you provide as of screen shot of the word ?

Hi @lucasferreira.lf00 ,

When dealing with word documents, we would have to perform some more operations in order to get the Desired expected output format.

Here, we would like to know How are the Questions arranged / also if there are choices available in it. We can then deduce a pattern and maybe use regex to extract all the Questions from the Document grouping each questions so that we can select the questions randomly.

In order to correctly understand your requirement, we would need sample of the input data and How would you like it to be presented as the expected Output.

If you still have an option to choose between Word/Excel, to make it simpler, an Excel spreadsheet could be used.

Let us know your thoughts and further inputs.

Hello!!

I share below the model of the question base used, in this model there are 28 questions and I would need to select 15 of them at random to generate a test, the questions are in Portuguese.
Base

This base does not necessarily need to be in Word, I can use Excel to assemble the base of questions as well.

As an output method, these randomized questions would need to be saved in a Word or Excel document to be uploaded to the platform where the test will be held.

Thanks for the support, guys!

Hello @lucasferreira.lf00

Here one option what you can do is , Read the Word file using Word Activity and then Split that output string using Split method with “16” as delimiter.

Split(Yourstringvariable,“16”)(0)

Thanks

Hi @lucasferreira.lf00 ,

Could you check the below workflow :
Random_Select_WordQuestions.zip (18.2 KB)

You would also need to install UiPath.Word.Activities dependency package in order for this to work.

Let us know if this doesn’t work or not giving the Expected result.

1 Like

Hello, @supermanPunch

Thank you so much, that was exactly what I needed!

Could you explain to me the logic and functions applied in this automation? If I want to replicate to an Excel file, will it be done in the same way?

Thanks again!

@lucasferreira.lf00 ,

Since we are dealing with Word documents, the need for Word Activities pack is a must in order for us to read the data as Text (String), Pick up the Questions as required using String Manipulations and then Write the Data Back.

The Steps are explained briefly below :

  1. Read Text Activity :
    image
  • Reads the Input word document that is supplied to it.
  • Gets the Output in the form of String or text data.
  1. Declare a Random type and initialise it.
    image
  • This is the key step/steps for selecting the questions at random.
  1. Split the text data into array of Strings making each item in the array a Single Question.
    image
  • Here, Regex methods are applied for proper split of the Combined Questions into Individual questions.
  • We test/check the patterns using .net regex / regex 101 applications/ UiPath’s Matches Activity and apply the pattern to our Expressions.
  • We get the Output as Array of Strings with each item a Individual Question.
  1. Ordering of the individual Questions and Converting to String.
    image
  • Here, we use Linq method OrderBy to perform the Random Ordering on array using the random object created.
  • We then take the Required number of questions using the Take(15) as 15 was the required number.
  • Next, As the Numbering of the Questions also resides along with it’s text data, we would need to re-order the number according to the new ordering. the Select(x,i) uses the Ordered questions one by one along with it’s index number, we then use regex replace method to replace just the number, thus modifying the value for the Selection.
  • As we now have the required output in the form of Array, we would have to convert back to string which can be done using String.Join().
  1. Word Application Scope - Append Text Activity
    image
  • As we have the Output (Ordered Random Questions from Input), we could write it to a Different word file. Which you could then use for later operations.

The explanation might not cover everything, but do read more on the topics Regex and Linq below for better understanding :

For this the logic would be the same, it’s just that we would have to apply Datatable methods as we are reading the data from Excel and perform Similar operations on it as well. But it also depends on how the data is formatted/Structured in the excel sheet.

Hello, @supermanPunch

I understood the concepts, thanks for the explanation and attention!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.