Source language: Translate to:

Random usage

General questions about NeoBook

Moderator: Neosoft Support

Random usage

Postby stu » Sun Sep 21, 2014 4:47 pm

I been trying to generate a random group of numbers for a while without success... So I thought of posting my question and see if someone can help out =)

The thing is, having like 5 vars and fill them with randomly generated numbers without repeating the numbers:

Eg:
4, 2, 1, 0, 3 <----- OK
1, 1, 0, 2, 2 <----- WRONG

?
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Random usage

Postby Gaev » Sun Sep 21, 2014 6:18 pm

stu:

The thing is, having like 5 vars and fill them with randomly generated numbers without repeating the numbers:

Eg:
4, 2, 1, 0, 3 <----- OK
1, 1, 0, 2, 2 <----- WRONG

Take a look at this article on my website ... http://www.scriptedlogic.com/zzold/neoHOW2.htm ... titled Non-repetitive Random Selection of items from a list.

Instead of names of fruit, you can do ...
Code: Select all
SetVar "[myInitialFruits]" "!/0,/1,/2,/3,/4,"
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Random usage

Postby virger » Mon Sep 22, 2014 8:24 am

Hi, maybe this button cant help you
DESDE COSTA RICA
PURA VIDA
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=3
Name=BtExe
X=87
Y=38
W=69
H=33
Anchor=0
Text=Exe
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[Tot]" "100"¶Loop "1" "[Tot]" "[Cc]"¶:Otro¶    Random "100" "[Rnd]"¶    if "[Tmp[Rnd]]" "<>" ""¶        GotoLine "Otro"¶    endif¶    setvar "[Data[Cc]]" "[Rnd]"¶endloop¶DeleteArray "[Tmp]" "All"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 523
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Random usage

Postby stu » Tue Sep 30, 2014 5:41 pm

Thanks a lot for your replies...

Gaev's approach is just what I was looking for, very cleaver way of doing the trick, I just include a while cycle and was working perfect in a sec.

Thanks again!
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 2 guests