Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 17th, 2024, 9:00 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Random Problem
PostPosted: November 8th, 2004, 3:44 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Script Object

function RandomList(number) {
numberlist = new Array();
for (count = 1; count <= number; count++) {
numberlist[count] = count;
}
randomlist = new Array();
for (count = numberlist.length - 1; count > 0; count--) {
picked = Math.floor(Math.random()*count)+1;
randomlist[count-1] = numberlist[picked];
numberlist[picked] = numberlist[count];
}
}

I have been trying to solve two (last I hope!) problems using as a basis the script above, kindly provided by Robin Garrett, but without success.

1. Using a single button I want to be able to Left Mouse Click and display an object selected at random from a list of objects obj_1 through to obj_whatever. When the button is clicked again the object shown should disappear to be replaced by another selected at random from the list of objects, and this to continue until all objects have been shown at random – without repetition, or until the user decides to end the activity. Hide and show is not the problem - but random certainly is!

2. The other aim is to operate on the same principle but to set a number, say 25, and each click selects at random a different object from say 50 objects. Again until all 25 objects have been shown at random – without repetition, or until the user decides to end the activity.

I’ve tried setting RandomList(number) on a button with a variety of counts of i to randomlist but I cannot get anything to happen.

Any help would be greatly appreciated.

John


For this message JMahoney has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 8th, 2004, 7:58 pm 
Offline

Joined: November 3rd, 2004, 7:18 pm
Posts: 8
Location: New Zealand
Hi John,
what are you building?
It might help us understand what you want.

cheers
Paul


For this message Paul Gresham has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Random Problem
PostPosted: November 8th, 2004, 9:04 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
See I got moved over from basics!

Hi Paul,

I'm attempting to build a series of activities on literary texts that can be used via an interactive whiteboard.

At the moment I want to give a couple of options.

1. Present a series of quotes, questions and so forth which change each time the 'selector' button is clicked. But the next time this exercise is used the order of presentation is randomised to prevent predictability.

2. Exactly the same as first option, except up to say, 30 quotes, questions etc are chosen at random from a larger base of questions.

All questions are 'hidden' on screen. I understand that I might be better having a separate database of questions external in an access file. But I really would prefer not to get involved in learning yet another routine and yet another set of problems about how to access them in various random configurations!

Hope this helps.

John


For this message JMahoney has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 9th, 2004, 12:16 am 
Offline

Joined: November 3rd, 2004, 7:18 pm
Posts: 8
Location: New Zealand
Hi John
This is quite a complex structure you are putting together --
The options you give look like they are similar in concept (more or less) to a quiz that selects a number of random questions from a larger pool.
I would search the old DW forum (before it disappears) and John's forum for anything to do with random selections, random question quiz, etc.
cheers
Paul


For this message Paul Gresham has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: November 9th, 2004, 5:30 am 
Offline

Joined: October 26th, 2004, 1:26 pm
Posts: 262
Hi John,

Would the "Show in Turn" Random Order (Miscellaneous Actions) be of help?

Just wondering if you could use this feature somehow for what you want? You may even get away without using complex scripting. :)

_________________
Cheers,
Steve


For this message Steve H has been thanked by : mackavi


Top
 Profile  
 
 Post subject: random
PostPosted: November 9th, 2004, 9:13 am 
Hi,

Perhaps these lines can help you.

...
//search number between 1 and 50
hasard=(Math.round(Math.random()*49))+1

//call a script object
newnumber()

...
//test if the randomised number wasn't used before
function newnumber()
{
//memorise hasard with "-" at begin and end
numbertotest="-"+String.string(hasard)+"-"

//listusednumber : list of good randomised numbers
//listusenumber is sthg like this : "-2-10-9-15"
//search for numbertotest in listusednumber
numberexist=String.contains(listusednumber,numbertotest)

while (numberexist==true)
{
//then hasard have to be changed while it exist in listusednumber
hasard=(Math.round(Math.random()*49))+1
numbertotest="-"+String.string(hasard)+"-"
numberexist=String.contains(listusednumber,numbertotest)
}
//add the good number to the list
listusednumber=listusednumber+numbertotest
}

//at the end of newnumber function, value of hasard is the good one, never used before.
//forgive my bad english


Top
   
 
 Post subject:
PostPosted: November 9th, 2004, 12:02 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Hi John,

Thank you for your enquiry.

The following script should satisfy both of your requirements:

Code:
function RandomList(number) {
numberlist = new Array();
for (count = 1; count <= number; count++) {
numberlist[count] = count;
}
randomlist = new Array();
for (count = numberlist.length - 1; count > 0; count--) {
picked = Math.floor(Math.random()*count)+1;
randomlist[count-1] = numberlist[picked];
numberlist[picked] = numberlist[count];
}
}

num = 0

function ShowRandom(limit) {
if (num == 0) {
eval("Text" + randomlist[num] + ".Show()")
num++
}
else if (num < limit) {
eval("Text" + randomlist[num-1] + ".Hide()")
eval("Text" + randomlist[num] + ".Show()")
num++
}
else {
eval("Text" + randomlist[num-1] + ".Hide()")
}
}


Please find below a link to download a working demonstration of this script.

To increase the length of the list of random numbers, simply adjust the value of the 'number' parameter which is sent to the RandomList() function (this script action is attached to an On Show trigger on the page).

To limit the number of objects which are shown (as per your second requirement), simply adjust the 'limit' parameter which is sent to the ShowRandom() function (this script action is attached to a Left Mouse Click trigger on the button).

For example, to generate a list of 50 random numbers (or, to be more precise, a shuffled list of the numbers 1 to 50), edit the script action on the page to read the following:

Code:
RandomList(50)


If you only want to show 25 random objects, edit the script action on the button to read the following:

Code:
ShowRandom(25)


I hope this helps. Please do not hesitate to contact me if you have any further queries.

Kind regards,


You do not have the required permissions to view the files attached to this post.

_________________
Robin Garrett
Digital Workshop Technical Support


For this message Robin Garrett has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Randon Problem
PostPosted: November 9th, 2004, 8:28 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Many thanks Paul, Steve and 'Guest'. Your interest and help is greatly appreciated.

Very many thanks :D Robin :D The solution is great.

I'll do my very best to stay off the topic of random selection over the next few months - hopefully :twisted:

All the very best

John


For this message JMahoney has been thanked by : mackavi


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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