electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
how do you maipulate an array with rand2()?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
laserbeak



Joined: Nov 12, 2006
Posts: 15
Location: East Coast U.S.Ass

PostPosted: Mon Nov 13, 2006 6:40 pm    Post subject: how do you maipulate an array with rand2()?
Subject description: trying to access an array with rand2()?
Reply with quote  Mark this post and the followings unread

hi
i'm trying to access an array with rand2() but i get syntax errors:

Code:

while( true )
{   
   //1 bar at 180bpm cut into 8ths
   float push[ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ]
    push[Math.rand2(0,7)] => buf.pos;
   
    1333::ms => now;
}
Back to top
View user's profile Send private message
laserbeak



Joined: Nov 12, 2006
Posts: 15
Location: East Coast U.S.Ass

PostPosted: Mon Nov 13, 2006 8:02 pm    Post subject: Reply with quote  Mark this post and the followings unread

i noticed my syntax errors in comparison to otf_06.ck on page 49 in the manual and re-wrote it.
Code:

// time loop
while( true )
{   
   //1 bar at 180bpm cut into 8ths
   [ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ]@=> float push[];
    push[Math.rand2(0,7)] => buf.pos;
   
    1333::ms => now;
}



but i still get this error: [SndBufTest1.ck]:line(19): array init [...] contains incompatible types...
Back to top
View user's profile Send private message
laserbeak



Joined: Nov 12, 2006
Posts: 15
Location: East Coast U.S.Ass

PostPosted: Mon Nov 13, 2006 8:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

ok so i realise the the .pos command is int
so then i rounded all my values to the highest whole value and made the array an int. i dont get any errors anymore but Chuck acts as if the array isnt even there.

Code:

while( true )
{   
   //1 bar at 180bpm cut into 8ths
   [ 0, 167, 333, 500, 667, 833, 1000, 1166 ] @=> int push[];
    push[Math.rand2(0,7)] => buf.pos;
    1333::ms => now;
}
Back to top
View user's profile Send private message
majutsu



Joined: Jun 18, 2006
Posts: 151
Location: New York
Audio files: 1

PostPosted: Mon Nov 13, 2006 9:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

for starters
try Std.rand2()
it's std namespace, not math, i believe.

furthermore, Std.rand() generates a random number between 0 and 1. rand2(min, max) generates a random number between min and max, you have no values, so you always generate zero i think.

good luck.

Last edited by majutsu on Mon Nov 13, 2006 9:19 pm; edited 1 time in total
Back to top
View user's profile Send private message
laserbeak



Joined: Nov 12, 2006
Posts: 15
Location: East Coast U.S.Ass

PostPosted: Mon Nov 13, 2006 9:18 pm    Post subject: Reply with quote  Mark this post and the followings unread

ok
did it.
no errors but no desired effect either
Back to top
View user's profile Send private message
majutsu



Joined: Jun 18, 2006
Posts: 151
Location: New York
Audio files: 1

PostPosted: Mon Nov 13, 2006 9:20 pm    Post subject: Reply with quote  Mark this post and the followings unread

please read rest of post you were typing while i was on first paragraph Very Happy

anxious to get started i see. that's good!

_________________
All phenomena are atoms in association and dissociation.
Back to top
View user's profile Send private message
laserbeak



Joined: Nov 12, 2006
Posts: 15
Location: East Coast U.S.Ass

PostPosted: Mon Nov 13, 2006 9:25 pm    Post subject: Reply with quote  Mark this post and the followings unread

hehe yes i'm quite anxious Smile
but i do have values(i think)
push[Std.rand2(0,7)] => buf.pos;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use