Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 18th, 2024, 11:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Random not quite random
PostPosted: April 18th, 2019, 3:33 pm 
Offline

Joined: May 31st, 2011, 11:20 pm
Posts: 37
Opus: Pro 09
OS: XP Pro
System: Various systems
Hi Everyone

I'm displaying some questions inside an EXE, and I have 35 of them. I've asked Opus to randomly select a variable up to 35, and it displays that question number (so if VARIABLE = 4, then question #4 displays) and it holds the number in another variable with parenthesis around it (4) in another variable to keep track of what questions were asked so it does not repeat the question. If it picks a number it picked before, it keeps running the routine until it picks a number not present in the USEDQUESTIONS variable.

Problem: when I run the tool within OPUS it returns between 26 and 30 results, but it never gets to 35. Sometimes it does 28, other times 26, other times 30, but it never exhausts all 35 questions. I can see the question numbers it misses, and it is different every time, suggesting to me that there are some numbers the RANDOM command will never select.

Anyone have this trouble or have a work-around?


For this message jmateus has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Random not quite random
PostPosted: April 22nd, 2019, 10:02 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
I don't use the Random action but a simple test that outputs the random value 500 times does show that each number up to 35 appeared at least once.

How often each number appears or could appear is a question for the mathematicians out there.

Opus does have a random page function that allows you to draw random pages from a chapter until the page pool is depleted. I think this is probably what you need.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Random not quite random
PostPosted: April 23rd, 2019, 2:09 pm 
Offline

Joined: May 31st, 2011, 11:20 pm
Posts: 37
Opus: Pro 09
OS: XP Pro
System: Various systems
Hi Mack - long time!

No, I need to pull a random question out of a bank without repeating it, so I'm asking the RANDOM function to pick a question number, then I'm saving that question number in a variable surrounded by parenthesis so that a 1 does not get picked up when question number (12) is saved. Basically, I'm searching for (x) in a string that looks like (a)(b)(ab)(bc)(x)(xb), and if (x) is found I search again.

After 28-30 tries it just keeps searching and searching indefinitely. Do you think the CONTAINS command would pick up a (1) when the variable holds (10)? would it just try to match the characters without order? That could be responsible for the issue.


For this message jmateus has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Random not quite random
PostPosted: April 23rd, 2019, 2:34 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Sorry don't know about contains.

But as you're using script commands, this method is what I'd normally use:

Code:
myQuestionsArray = new Array(1,2,3,4,5,6,7,8,9.10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35)

shuffle(myQuestionsArray);

Debug.trace(myQuestionsArray)

function shuffle(array) {
var m = array.length, t, i;

while (m) {

i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}

return array;
}


The myQuestionsArray is a fixed set of the numbers your using - so you can only access each number only once. You then shuffle the array, so they are in a random order.

Then just pick one number at a time using the array index. IE myQuestionsArray[0] then myQuestionsArray [1] then myQuestionsArray [2]

You can also use a variable as the index value and just update the variable.

Hope that helps

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Random not quite random
PostPosted: April 24th, 2019, 5:12 pm 
Offline

Joined: May 31st, 2011, 11:20 pm
Posts: 37
Opus: Pro 09
OS: XP Pro
System: Various systems
I'm using scripting, but in the way a toddler walks - just barely!

I'm actually using the canned commands in the PROGRAMMING actions tab. It has a feature for CONTAINS which is how I'm picking out the question.

I tried the below, but I'm clearly not familiar enough with javascript. The array idea is a good one. I will likely use it as soon as I can figure out how to call up the commands.

Question - is a variable created with javascript not the same as one made 'within' OPUS? I'm trying to use javascript to write to a variable created with OPUS' NEW VARIABLE command, but it does not seem to work.


For this message jmateus has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Random not quite random
PostPosted: April 25th, 2019, 9:11 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
OpusScript isn't JavaScript. They are both 'dialects' of ECMAScript - and at one point where very similar but in recent years JavaScript has seriously evolved and the syntax and functionality of modern ECMAScript / JS would likely fail in the OpusScript object or action.

The answer to your question, is that if you create a script variable in either a script Object or a script Action then it depends on whether you declare it using 'var'.

Personally, for simple OpusScript I would simply avoid declaring variables in scripts using 'var' unless you are using it inside a function.

I created a sample project using the shuffle function:

download from here: http://www.live.interaktiv.co.uk/?section=files

using the following code (copy and paste): shuffle@digitalgrapevine.info

Hopefully it will give you some pointers.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group