Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 3:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: question about random numbers
PostPosted: February 10th, 2009, 2:20 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
How can i tell the random function to skip numbers that already been taken.

Kind regards,

Ad


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 10th, 2009, 2:26 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
You can't.

Depending on what your doing it's probably best to call a number from a depleting randomised pool.

This can be achieved by populating an array with your number set and randomising the array. Then you simply work through each element in order.

The function to randomise the array has been posted several times on the forum.

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:
PostPosted: February 10th, 2009, 2:45 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
Hi Macavi,

I found another way to do it.
On the first page i put all the numbers.
After picking a random number let's say number 6 i go to the next page and tell the button to pick random over only 5 numbers etc.
I am working on it right now. Keep you informed.


Ad


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 21st, 2009, 6:10 pm 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
I have used this for creating a random order of non repeating, works very well. If you have numberFeatures of say 5, it will randomly create an array of number of 0 - 5, non repeating and then use this as your list.

Code:
function createArray()
{
   for (var i = 0; i < numberFeatures; i++)
   {
   randomFeatureQuestion[i] = i;
   Debug.trace(randomFeatureQuestion[i] + "\n");
   }
      
fisherYates(randomFeatureQuestion);
Debug.trace("randomFeatureQuestion " + randomFeatureQuestion + "\n");
}


function fisherYates(myArray)
{
var i = myArray.length;
if ( i == 0 ) return false;

   while ( --i )
   {
   var j = Math.floor( Math.random() * ( i + 1 ) );
   var tempi = myArray[i];
   var tempj = myArray[j];
   myArray[i] = tempj;
   myArray[j] = tempi;
   }
}

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


Top
 Profile  
 
 Post subject:
PostPosted: February 21st, 2009, 8:49 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
Well the option i suggested didn't work so let's try your script Imc


Ad

_________________
Opus Pro v9.75
Windows 10 on HP EliteBook i7
http://www.csnmedia.nl


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 22nd, 2009, 2:00 pm 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
How I normally work random questions non-repeating it.

I read the questions into an array featureArray[], then I use the code above to create a random sequence of another array randomFeatureQuestion[] based on the number of features in featureArray[].


I then use the following to call each question:

Code:
var QuestionNo = randomFeatureQuestion[nextQuestion];
Question = featureArray[QuestionNo];
nextQuestion = nextQuestion + 1;



This should work above, it's nice and simple to implement. Out put example from everything would be.

Say you have 5 questions, the randomFeatureQuestion[] would be populated with a random sequence of numbers up to 5 (as array counted from 0). So the sequence could be 4,0,1,3,2. This sequence is then used to call the array number in the featureArray[].

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


Top
 Profile  
 
 Post subject:
PostPosted: February 22nd, 2009, 8:42 pm 
Offline

Joined: July 11th, 2008, 7:44 pm
Posts: 16
Location: Oss, The Netherlands
Oops, thats iteresting, but too difficult for me. Do you have an example .imp so i can analyse it and implement it in a small game i am working on.

Marian


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 41 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