Welcome Hashim
I need some clarification of your question. The random function as described in the dictionary should provide a sufficiently random sequence and, as described under randomSeed, the starting point will be different each time you load the application.
It is possible to use the randomBytes property either to generate a new seed yourself or to construct the entire random sequence, though I think either would be overkill for a flags game, and randomBytes is much slower.
David
Creating a randomizer that does not repeat picks
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Creating a randomizer that does not repeat picks
Hello! Welcome to LC and the LC forums! Here's how I would do it though I may be missing something.Hashim_553 wrote: ↑Sat Feb 13, 2021 9:46 pmHi I'm not only new to liveCode I'm also new to this website so I replied to this post.
I'm making a flags game and I'm trying to make the fags randomized and not repeated so I'm trying to make a randomizer that doesn't repeat itself how do I do that?
Code: Select all
local flag -- Declares a new local variable
put "US,UK,Ireland,Germany,France,Switserland,Brasil,Israel,Iran" into tFlags -- Puts a list of countrys into a temporary variable "tFlags", you can istaed put the names of the graphics etc.
split tFlags by comma -- Splits the variable "tFlags" into an array, --> tFlags [0] would be "US", tFlags[1] would be "UK" etc.
put the number of elements of tFlags into tLegnth -- Puts the legnth of the new array into temporary variable "tLegnth"
put random(tLegnth) into tKey -- Chooses a random key (because remember the keys of tFlags are numbers) of the array "tFlags"
put tFlags[tKey] into flag -- Puts the element of the random key into "flag"
delete variable tFlags[tKey] -- Removes the flag chosen from the array.
-
- VIP Livecode Opensource Backer
- Posts: 9582
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Creating a randomizer that does not repeat picks
@ Hashim.
Perhaps a simpler test that you can play with. Make two fields. In fld 1 put several short lines of text. Lock the text of field 1. Put this in the field 1 script;
Click anywhere in field 1, and random lines of its text will build in field 2, and disappear from field 1.
Can you modify the script so that the line clicked on field 1 builds in fld 2, and is then deleted from field 1?
Craig
Perhaps a simpler test that you can play with. Make two fields. In fld 1 put several short lines of text. Lock the text of field 1. Put this in the field 1 script;
Code: Select all
on mouseup
put random(the number of lines of me) into tLine
put line tLine of me & return after fld 2
delete line tLine of me
end mouseup
Can you modify the script so that the line clicked on field 1 builds in fld 2, and is then deleted from field 1?
Craig